Google ADK

This guide demonstrates how to use SEA-LION models as intelligent agents using Google's Agent Development Kit (ADK). The examples show how to build both general-purpose agents with multiple tools and specialized single-purpose agents.

Prerequisites

The sample code in this guide will be configuring the model via SEA-LION API through LiteLLM, which follows an OpenAI-compatible format. Google ADK is also compatible with other model providers including Google's own Vertex AI. For configuring SEA-LION in Google ADK, you may refer to this page. Click here for instructions on deploying SEA-LION in Vertex AI.

Environment Setup

Create a .env file with your configuration:

## For using SEA-LION API, uncomment if needed
OPENAI_API_KEY=your-sea-lion-api-key-here
OPENAI_API_BASE=https://api.sea-lion.ai/v1
MODEL=aisingapore/Llama-SEA-LION-v3-70B-IT

## For using Google Vertex AI, uncomment if needed
# GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
# GOOGLE_CLOUD_LOCATION="YOUR_VERTEX_AI_LOCATION" # e.g., us-central1
GOOGLE_GENAI_USE_VERTEXAI=TRUE # Set to TRUE if NOT using Google AI Studio, due to function declaration issue: https://github.com/google/adk-python/issues/26#issuecomment-2911749485

# Environment variable for custom tool
SEARXNG_URL=https://your-searxng-instance-url-here

Project Structure

Basic Agent Setup

Here's how to create a basic SEA-LION agent with tool-calling capabilities:

agent.py

__init__.py

Custom Tool Development

You can create custom tools for your agents. Here's an example of custom web search tool using a locally-deployed SearXNG search engine:

tools.py

Agent as a Tool

Create a specialized agent that can be used as a tool by other agents:

translator.py

Running the Agent

Google ADK provides a built-in web interface. Simply run:

This will start a web server accessible at http://localhost:8000 using your agent.py configuration.

CLI Interface (Optional)

For command-line interaction, you can use the optional CLI script:

chat-cli.py

To run the CLI:

Best Practices

Model Selection

  • Use aisingapore/Llama-SEA-LION-v3-70B-IT for complex reasoning and tool-calling

  • Use aisingapore/Gemma-SEA-LION-v3-9B-IT for specialized, single-purpose agents

Agent Configuration

  • Use clear, descriptive names for your agents

  • Provide specific instructions about tool usage guidelines

  • Include examples when tools have specific parameter formats

  • Clearly define the agent's role and capabilities

Session Management

  • Google ADK uses session-based interactions for maintaining context

  • Use InMemorySessionService for development and testing

  • Consider persistent session storage for production applications

  • More information and examples on session/memory management available here

Tool Documentation

Always provide clear docstrings for custom tools, including:

  • Purpose and functionality

  • Parameter descriptions with types

  • Return value format

  • Usage examples

  • Exception handling

Troubleshooting

Common Issues:

  1. Tool not being called: Ensure your instruction mentions the tool and its use cases

  2. LiteLLM connection errors: Verify your API keys and base URLs in the .env file

  3. Function declaration issues: Set GOOGLE_GENAI_USE_VERTEXAI=TRUE if not using Google AI Studio

  4. Session creation failures: Check your session service configuration and permissions

  5. Async/await issues: Ensure proper async handling in CLI implementations

Performance Tips:

  • Use appropriate model sizes for your use case

  • Implement proper error handling and fallbacks

  • Monitor token usage to optimize costs

Google ADK Specific:

Last updated