# mk-agents-python-sdk-tutorial let's make this a very basic tutorial on the agents api ## steps ### basics - create python notebook in google colab - get all your secret stuff together and add it to secrets. The bare minimum will be a value for `OPENAI_API_KEY`. - Mount Google Drive so you can read and write files. ``` from google.colab import drive drive.mount('/content/drive') ``` - get and store your secret values (only include the ones you want to use) ``` from google.colab import userdata OPENAI_API_KEY = userdata.get('OPENAI_API_KEY') SLACK_WEBHOOK_URL = userdata.get('SLACK_WEBHOOK_URL') AIRTABLE_API_KEY = userdata.get('AI_LAB_AIRTABLE_API_KEY') AIRTABLE_BASE_ID = userdata.get('AI_LAB_AIRTABLE_BASE_ID') ``` - if you want to define an input or output folder or path, do that ``` output_folder="/content/drive/MyDrive/ll_color_colabs/_projects/_ai-lab-planning/openai_agents_sdk_tutorials/output" ``` - install the openai and openai-agents packages ``` !pip install openai, openai-agents ``` - do your first basic openai call to test and you should see a response ``` from openai import OpenAI client = OpenAI(api_key=OPENAI_API_KEY) response = client.responses.create( model="gpt-4o", input="Write a one-sentence bedtime story about a unicorn." ) print(response.output_text) ``` - investigate the content of the response in different ways, first to get json: ``` print(response.model_dump_json(indent=2)) ``` - and then to see the "help" docs (which is how you would have found out about `response.output_text` if you didn't know it was there) ``` help(response) ``` ### agents For traces to work (a way of tracking what you're doing) we've found you need to do this (well, at least the second): ``` from agents import set_default_openai_key, set_tracing_export_api_key set_default_openai_key(OPENAI_API_KEY) set_tracing_export_api_key(OPENAI_API_KEY) ``` ## sidequests - [file search](https://platform.openai.com/docs/guides/tools-file-search) - [vector stores](https://platform.openai.com/docs/guides/embeddings) - [notes on retrieval](https://platform.openai.com/docs/guides/retrieval) - [conversation state](https://platform.openai.com/docs/guides/conversation-state?api-mode=responses) - ## links and to-dos - [OpenAI Agents SDK Docs on the github.io page](https://openai.github.io/openai-agents-python/) - and the [OpenAI Agents SDK Docs on the OpenAI API docs page](https://platform.openai.com/docs/guides/agents-sdk). `#TODO: at some point we'll want to check to see if these are different` - - direct [link to md doc in the repo that describes agent ensemble handoff patterns](https://github.com/openai/openai-agents-python/blob/main/examples/agent_patterns/README.md). And here is a version for us to copy paste or add to in hackmd: [openai-common-agentic-patterns](/U_BSNbHNQ4uuA2tNb-Km4g) - dev - [mk-working-folder](https://drive.google.com/drive/folders/16ct5o29ic9jywIXa6DQZcAiJB0rwDy8C?usp=drive_link) - [openai builder lab repo](https://github.com/openai/openai-builder-lab/tree/main) seems like the monorepo to imitate more or less in tutorials? - https://github.com/openai/openai-realtime-console - ## knowledge base - [openai-openapi-schema](https://github.com/openai/openai-openapi/blob/master/openapi.yaml) ## questions - should we also involve langchain and langraph? got this far in a useful video: <iframe width="560" height="315" src="https://www.youtube.com/embed/aHCDrAbH_go?si=IZPJ__jcPnTgmRx2&amp;start=410" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> ### langGraph comparisons https://langchain-ai.github.io/langgraph/tutorials/introduction/