Skip to main content

Multi-model provider implementations for OpenAI Agents, supporting both OpenAI and Ollama models

Project description

Timestep

Multi-model provider implementations for OpenAI Agents, supporting both OpenAI and Ollama models. Works with both local Ollama instances and Ollama Cloud.

Installation

pip install timestep

Quick Start

Using MultiModelProvider (Recommended)

The MultiModelProvider automatically routes requests to the appropriate provider based on model name prefixes:

from timestep import MultiModelProvider
from agents import Agent

# Create a provider that supports both OpenAI and Ollama
provider = MultiModelProvider(
    openai_api_key="your-openai-key"  # Optional, uses default if not provided
)

# Create an agent that can use any model
agent = Agent(
    model="gpt-4",  # Uses OpenAI
    provider=provider
)

# Or use Ollama models
agent = Agent(
    model="ollama/llama3",  # Uses Ollama
    provider=provider
)

Using OllamaModelProvider Directly

from timestep import OllamaModelProvider
from agents import Agent

# Create an Ollama provider for local Ollama instance
ollama_provider = OllamaModelProvider(
    base_url="http://localhost:11434"  # Optional, defaults to localhost
)

# Create an agent using Ollama
agent = Agent(
    model="llama3",
    provider=ollama_provider
)

# For Ollama Cloud, use the API key
cloud_provider = OllamaModelProvider(
    api_key="your-ollama-cloud-key",
    base_url="https://ollama.com"  # Optional, auto-detected for models ending with "-cloud"
)

# Or provide a custom Ollama client
from ollama import AsyncClient
custom_client = AsyncClient(host="http://custom-host:11434")
custom_provider = OllamaModelProvider(ollama_client=custom_client)

Using OllamaModel Directly

from timestep import OllamaModel
from ollama import AsyncClient

# Create an Ollama client
client = AsyncClient(host="http://localhost:11434")

# Create a model instance directly
model = OllamaModel(model="llama3", ollama_client=client)

# Use with agents
from agents import Agent
agent = Agent(model=model)

Custom Provider Mapping

from timestep import MultiModelProvider, MultiModelProviderMap, OllamaModelProvider
from agents import Agent

# Create a custom mapping
provider_map = MultiModelProviderMap()
provider_map.add_provider("custom", your_custom_provider)

# Use the custom mapping
provider = MultiModelProvider(
    provider_map=provider_map,
    openai_api_key="your-key"
)

agent = Agent(
    model="custom/my-model",
    provider=provider
)

Components

MultiModelProvider

Automatically routes model requests to the appropriate provider based on model name prefixes. Supports both OpenAI and Ollama models out of the box.

Features:

  • Automatic provider selection based on model name prefix
  • Default fallback to OpenAI for unprefixed models
  • Support for custom provider mappings

OllamaModelProvider

Provides access to Ollama models (local or cloud).

Options:

  • api_key (str, optional): API key for Ollama Cloud
  • base_url (str, optional): Base URL for Ollama instance (defaults to http://localhost:11434 for local, https://ollama.com for cloud)
  • ollama_client (Any, optional): Custom Ollama client instance

Features:

  • Lazy client initialization (only loads when needed)
  • Automatic cloud detection for models ending with -cloud
  • Support for both local Ollama instances and Ollama Cloud
  • Seamless switching between local and cloud models

OllamaModel

Direct model implementation that converts Ollama responses to OpenAI-compatible format.

Features:

  • Converts Ollama API responses to OpenAI format
  • Supports streaming responses
  • Handles tool calls and function calling
  • Compatible with OpenAI Agents SDK

MultiModelProviderMap

Manages custom mappings of model name prefixes to providers.

Methods:

  • add_provider(prefix, provider): Add a prefix-to-provider mapping
  • remove_provider(prefix): Remove a mapping
  • get_provider(prefix): Get provider for a prefix
  • has_prefix(prefix): Check if prefix exists
  • get_mapping(): Get all mappings
  • set_mapping(mapping): Replace all mappings

Features

  • Multi-Model Support: Seamlessly switch between OpenAI and Ollama models
  • Automatic Routing: Model names with prefixes (e.g., ollama/llama3) automatically route to the correct provider
  • Customizable: Add your own providers using MultiModelProviderMap
  • OpenAI Compatible: Works with the OpenAI Agents SDK
  • Ollama Integration: Full support for both local Ollama instances and Ollama Cloud

Model Naming

  • Models without a prefix (e.g., gpt-4) default to OpenAI
  • Models with openai/ prefix (e.g., openai/gpt-4) use OpenAI
  • Models with ollama/ prefix (e.g., ollama/llama3) use Ollama

Requirements

  • Python >=3.11
  • ollama >=0.6.0
  • openai-agents >=0.4.2

Future Plans

We're actively developing additional features for the timestep library:

  • Additional Abstractions: Gradually abstracting out other logic from Timestep AI into reusable library components
  • CLI Tool: A proper command-line interface with tracing support for debugging and monitoring agent interactions

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

timestep-2026.0.2.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

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

timestep-2026.0.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file timestep-2026.0.2.tar.gz.

File metadata

  • Download URL: timestep-2026.0.2.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for timestep-2026.0.2.tar.gz
Algorithm Hash digest
SHA256 e8150211e9c6b15035b87517e7d124435d285da4e9bfeee7d12d25926b5b4e92
MD5 9d514b7d80d9a7880b4e691c15071ec0
BLAKE2b-256 653de2f7181c7fc677d6db07271ea9ea97aff6ca50d4d7a48d305a9d4bc958d0

See more details on using hashes here.

File details

Details for the file timestep-2026.0.2-py3-none-any.whl.

File metadata

  • Download URL: timestep-2026.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for timestep-2026.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 437e4ffd462f36ab0f69d9127f31e232788c132f7445557debe925de6361545c
MD5 1fce412ba70c2266314f040595164dd7
BLAKE2b-256 80c5884af2e216b85fcab4f2c51a38a54a672cb66d65b6dabc961c83461c3460

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