Skip to main content

Model adapters for OpenAI Agents SDK

Project description

Agents SDK Models 🤖🔌

PyPI Downloads

Python 3.11+ OpenAI Agents

A collection of model adapters for OpenAI Agents SDK, allowing you to use various LLM providers with a unified interface! 🚀

🌟 Features

  • 🔄 Unified Interface: Use the same OpenAI Agents SDK interface with multiple model providers
  • 🧩 Multiple Models: Support for Ollama, Google Gemini, and Anthropic Claude
  • 📊 Structured Output: All models support structured output using Pydantic models

🛠️ Installation

From PyPI (Recommended)

# Install from PyPI
pip install agents-sdk-models

# For examples with structured output
pip install agents-sdk-models[examples]

From Source

# Clone the repository
git clone https://github.com/kitfactory/agents-sdk-models.git
cd agents-sdk-models

# Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\activate  # Windows
source .venv/bin/activate  # Linux/Mac

# Install the package in development mode
pip install -e .

🚀 Quick Start

Ollama

import asyncio
from agents import Agent, Runner
from agents_sdk_models import OllamaModel

async def main():
    # Initialize the Ollama model
    model = OllamaModel(
        model="llama3",  # or any other model available in your Ollama instance
        temperature=0.7
    )
    
    # Create an agent with the model
    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        model=model
    )
    
    # Run the agent
    response = await Runner.run(agent, "What is your name and what can you do?")
    print(response.final_output)

if __name__ == "__main__":
    asyncio.run(main())

Google Gemini

import asyncio
import os
from agents import Agent, Runner
from agents_sdk_models import GeminiModel

async def main():
    # Get API key from environment variable
    api_key = os.environ.get("GOOGLE_API_KEY")
    
    # Initialize the Gemini model
    model = GeminiModel(
        model="gemini-1.5-pro",
        temperature=0.7,
        api_key=api_key
    )
    
    # Create an agent with the model
    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        model=model
    )
    
    # Run the agent
    response = await Runner.run(agent, "What is your name and what can you do?")
    print(response.final_output)

if __name__ == "__main__":
    asyncio.run(main())

Anthropic Claude

import asyncio
import os
from agents import Agent, Runner
from agents_sdk_models import ClaudeModel

async def main():
    # Get API key from environment variable
    api_key = os.environ.get("ANTHROPIC_API_KEY")
    
    # Initialize the Claude model
    model = ClaudeModel(
        model="claude-3-sonnet-20240229",
        temperature=0.7,
        api_key=api_key,
        thinking=True  # Enable thinking for complex reasoning
    )
    
    # Create an agent with the model
    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        model=model
    )
    
    # Run the agent
    response = await Runner.run(agent, "What is your name and what can you do?")
    print(response.final_output)

if __name__ == "__main__":
    asyncio.run(main())

📊 Structured Output

All models support structured output using Pydantic models:

from pydantic import BaseModel
from typing import List

class WeatherInfo(BaseModel):
    location: str
    temperature: float
    condition: str
    recommendation: str

class WeatherReport(BaseModel):
    report_date: str
    locations: List[WeatherInfo]

# Create an agent with structured output
agent = Agent(
    name="Weather Reporter",
    model=model,
    instructions="You are a helpful weather reporter.",
    output_type=WeatherReport
)

# Get structured response
response = await Runner.run(agent, "What's the weather like in Tokyo, Osaka, and Sapporo?")
weather_report = response.final_output  # This is a WeatherReport object

🔧 Supported Environments

  • Operating Systems: Windows, macOS, Linux
  • Python Version: 3.11+
  • Dependencies:
    • openai>=1.66.2
    • openai-agents==0.0.4
    • pydantic>=2.10, <3 (for examples with structured output)

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgements

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

agents_sdk_models-0.0.5.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

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

agents_sdk_models-0.0.5-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file agents_sdk_models-0.0.5.tar.gz.

File metadata

  • Download URL: agents_sdk_models-0.0.5.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for agents_sdk_models-0.0.5.tar.gz
Algorithm Hash digest
SHA256 fde3f496ba77e86552e44742a95d77278a58a357dec6915df11d54927dedc5be
MD5 998e804ffae1974b8989fa56cd0e57f3
BLAKE2b-256 e90362ca4cb607827304bded30d7ab289a0e082836ca39a72ebc95c61d7679a5

See more details on using hashes here.

File details

Details for the file agents_sdk_models-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for agents_sdk_models-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 956ab362d5687ce8da433ae62db99d126012fd55df0f46895104bf9952170933
MD5 d1daf17db7fca236aa993bd81566aa57
BLAKE2b-256 fc6f12d17d1fd4920243882c13f2167cc0534313978d5fa5d7ce807033d0cdfc

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