Skip to main content

Production-ready AI agent framework purpose built for Vertex AI

Project description

em-agent-framework

A production-ready AI agent framework with support for Gemini and Anthropic (Claude) models via Vertex AI.

Features

  • Multi-Model Support: Seamless integration with Gemini and Anthropic models
  • Automatic Fallback: Cascading fallback across multiple models on failure
  • Parallel Tool Execution: Execute independent function calls concurrently
  • Context Injection: Pass large data/secrets to tools without sending through LLM
  • Group Chat: Multi-agent conversations with flexible routing strategies
  • Metrics & Observability: Built-in tracking for performance and usage

Installation

pip install em-agent-framework

Requirements

  • Python 3.8+
  • Google Cloud Project with Vertex AI enabled
  • Vertex AI API credentials configured

Quick Start

import asyncio
from typing import Annotated
from em_agent_framework.core.agent import Agent
from em_agent_framework.config.settings import ModelConfig, AgentConfig

# Define a tool
def get_weather(city: Annotated[str, "City name"]) -> str:
    """Get weather for a city."""
    return f"Weather in {city}: Sunny, 72°F"

async def main():
    # Configure models with fallback
    model_configs = [
        ModelConfig(name="gemini-2.0-flash-exp", provider="gemini"),
        ModelConfig(name="claude-3-5-sonnet-v2@20241022", provider="anthropic"),
    ]

    # Create agent
    agent = Agent(
        name="assistant",
        system_instruction="You are a helpful assistant.",
        tools=[get_weather],
        model_configs=model_configs,
        agent_config=AgentConfig(verbose=True)
    )

    # Send message
    response = await agent.send_message("What's the weather in Tokyo?")
    print(response)

asyncio.run(main())

Key Features

Model Fallback

Automatically falls back to alternative models if the primary model fails:

model_configs = [
    ModelConfig(name="gemini-2.0-flash-exp", provider="gemini"),  # Try first
    ModelConfig(name="claude-3-5-sonnet-v2@20241022", provider="anthropic"),  # Fallback
]

Parallel Tool Execution

Execute multiple independent function calls concurrently:

agent_config = AgentConfig(
    enable_parallel_tools=True,
    max_parallel_tools=5
)

Context Injection

Pass data to tools without sending it through the LLM (ideal for large datasets, API keys, or user info):

def analyze_data(metric: Annotated[str, "Metric to analyze"], context: dict) -> str:
    """Analyze user data."""
    df = context.get('dataframe')  # Not sent to LLM
    userid = context.get('userid')  # Not sent to LLM
    return f"User {userid}: Analysis complete"

agent = Agent(
    name="analyst",
    tools=[analyze_data],
    context={
        'dataframe': large_df,      # Never sent to LLM
        'userid': 'USER_12345',     # Never sent to LLM
    },
    model_configs=model_configs,
    agent_config=agent_config
)

Benefits:

  • Reduce token costs: Large data stays local
  • Security: Sensitive data (API keys, credentials) stays private
  • Authentication: Pass user info for validation

Dynamic Tool Loading

Load tools on-demand instead of all at once:

# Define tools
def basic_search(query: Annotated[str, "Search query"]) -> str:
    return f"Results for: {query}"

def advanced_analysis(data: Annotated[str, "Data to analyze"]) -> str:
    return f"Analysis of: {data}"

# Create agent with complementary tools
agent = Agent(
    name="assistant",
    tools=[basic_search],  # Loaded immediately
    complementary_tools=[advanced_analysis],  # Available via search_tool
    model_configs=model_configs,
    agent_config=agent_config
)

# Agent can dynamically load tools when needed
# Just mention the tool name and the agent will use search_tool to find and load it
response = await agent.send_message("Use advanced_analysis to analyze this data")

Dynamic Instructions

Load specialized instructions on-demand:

# Create instructions.json
{
    "instructions": [
        {
            "id": "code_review",
            "description": "Code review guidelines",
            "instruction": "Review code for: correctness, efficiency, security, readability"
        },
        {
            "id": "api_design",
            "description": "API design principles",
            "instruction": "Design RESTful APIs following best practices"
        }
    ]
}

# Create agent with instructions file
agent = Agent(
    name="assistant",
    system_instruction="You are a code assistant.",
    instructions_file="instructions.json",
    model_configs=model_configs,
    agent_config=agent_config
)

# Agent can load instructions dynamically
response = await agent.send_message("Load code_review instructions and review this code: ...")

Multi-Agent Group Chat

from em_agent_framework.core.group_chat.manager import GroupChatManager

# Create specialized agents
researcher = Agent(name="researcher", system_instruction="Research expert", ...)
developer = Agent(name="developer", system_instruction="Python developer", ...)

# Create group chat with skill-based routing
manager = GroupChatManager(
    agents=[researcher, developer],
    strategy="skill_based",  # Routes based on agent descriptions
    max_total_turns=10
)

# Start conversation
await manager.initiate_conversation(
    query="Research and build a JSON parser"
)

Configuration

Agent Configuration

AgentConfig(
    max_turns=100,              # Max conversation turns
    max_retries_per_model=3,    # Retries before fallback
    verbose=True,               # Print debug logs
    enable_parallel_tools=True, # Enable parallel execution
    max_parallel_tools=5        # Max concurrent tools
)

Model Configuration

ModelConfig(
    name="gemini-2.0-flash-exp",
    provider="gemini",          # "gemini" or "anthropic"
    temperature=0.1,
    max_output_tokens=8192,
    timeout=10.0               # Request timeout (seconds)
)

Testing

# Run all tests
pytest tests/ -v

# Run specific test
pytest tests/test_agent_basic.py -v

Development

git clone https://github.com/emergence-ai/em-agent-framework
cd em-agent-framework
pip install -r requirements.txt

License

Apache-2.0 License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

em_agent_framework-1.0.3.tar.gz (59.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

em_agent_framework-1.0.3-py3-none-any.whl (46.5 kB view details)

Uploaded Python 3

File details

Details for the file em_agent_framework-1.0.3.tar.gz.

File metadata

  • Download URL: em_agent_framework-1.0.3.tar.gz
  • Upload date:
  • Size: 59.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for em_agent_framework-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0967dd03165ddcb0daf6e2cbebcd75ac0c81b8aa63366f837a4409e6a46a9389
MD5 f4cb8b3f34b35211794bf4d67a369ce7
BLAKE2b-256 83cfb95fb627eacd4c8a90917eb20e107d461419dbadd6b7f71a3eb503f6b028

See more details on using hashes here.

File details

Details for the file em_agent_framework-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for em_agent_framework-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71e84017935995643379ee312642e50de92a87df37e3f6d120ea0fa9077e6132
MD5 e730963b2488c0e09a7973c9ab7fbc3e
BLAKE2b-256 6dfbc92898cba49f0742292aa0a28d1299caf7e01ca0d08a7c55c98e6cf052fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page