Example for OpenAI or any other LLM through the yaml config way #2581
-
|
Hi All, If someone has some example, can you please point me to that. I have looked at https://github.com/google/adk-python/tree/main/contributing/samples/tool_agent_tool_config and other examples, but all are based on gemini models. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Yes, you can use other LLMs like OpenAI with ADK by using the Hello! That's a great question. The Agent Development Kit (ADK) is designed to be flexible and supports a wide range of Language Models beyond Gemini, including those from OpenAI, Anthropic, Cohere, and many others through its integration with the While the examples you've seen might be centered on YAML for configuration, the standard way to incorporate other LLMs is to define the agent in a Python file and then reference that agent from your YAML configuration. Here’s a step-by-step guide on how you can achieve this: Step 1: Install LiteLLMFirst, you need to install the pip install litellmStep 2: Set Your API KeyADK, via LiteLLM, uses environment variables to authenticate with LLM providers. For OpenAI, you would set the export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"Step 3: Define Your Agent in PythonCreate a Python file (e.g., Here is an example of what that Python file would look like. [1] # File: my_agents/openai_agent.py
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
# Define an agent that uses OpenAI's GPT-4o model
my_openai_agent = LlmAgent(
model=LiteLlm(model="openai/gpt-4o"), # Using LiteLlm to specify the model
name="openai_agent",
instruction="You are a helpful assistant powered by OpenAI's GPT-4o.",
# You can add tools and other parameters here as usual
# tools=[...]
)Step 4: Reference the Agent in Your YAML ConfigNow, in your main YAML configuration file, you can reference the agent you defined in Python using the For example, if you have a root agent in YAML that you want to use your new OpenAI agent as a sub-agent, it would look like this: [14] # File: your_main_config.yaml
name: "root_agent"
model: "gemini-2.0-flash"
instruction: "You are a coordinator agent."
sub_agents:
- code: my_agents.openai_agent.my_openai_agentThis setup allows you to leverage the full power of Python for complex configurations (like using different model libraries) while still using YAML for the overall structure of your agent team. For more detailed information, you can refer to the ADK documentation on using different models and the tutorials on building agent teams. [1, 3] I hope this helps you get started! Let us know if you have any more questions. [1] https://google.github.io/adk-docs/agents/models/ |
Beta Was this translation helpful? Give feedback.
Hi @shivsant, there isn't any support for other non-Gemini models in the yaml config design yet. The feature is experimental, so we plan to gradually add more features to it. Right now non-Gemini models are planned.