aisuite README

The project's README from github.com/andrewyng/aisuite. As one markdown file: README.md.

OpenWorker

OpenWorker

A desktop AI coworker, built on aisuite — now in its own repository: andrewyng/openworker.

OpenWorker chats, does deep research, and carries out real tasks on your computer — reading files with permission, connecting to Slack/email, producing PDFs, documents, and spreadsheets, and running scheduled automations. Bring your own API key (OpenAI, Anthropic, Google) or run fully local with Ollama; your data stays on your machine.

⬇ Download for macOS macOS 13+ (Apple Silicon)  ·  ⬇ Download for Windows Windows 10/11 (x64)  ·  Quickstart

OpenWorker development has moved to the new repo. A historical snapshot of its source remains in openworker-archive/.


aisuite

PyPI Code style: black

aisuite is a lightweight Python library for building with LLMs, in two layers: a unified Chat Completions API across providers, and an Agents API with tools and toolkits on top. aisuite also powers OpenWorker, a desktop AI coworker developed in its own repository:

┌───────────────────────────────────────────────┐
│          OpenWorker  (separate repo)          │   agent harness for doing everyday tasks
├───────────────────────────────────────────────┤
│        Agents API  ·  Toolkits  ·  MCP        │   build agents across multiple LLMs
├───────────────────────────────────────────────┤
│             Chat Completions API              │   one API across multiple LLM providers
├────────┬───────────┬────────┬────────┬────────┤
│ OpenAI │ Anthropic │ Google │ Ollama │ Others │
└────────┴───────────┴────────┴────────┴────────┘

Installation

Install the base package, or include the SDKs of the providers you plan to use:

pip install aisuite               # base package, no provider SDKs
pip install 'aisuite[anthropic]'  # with a specific provider's SDK
pip install 'aisuite[all]'        # with all provider SDKs

You'll also need API keys for the providers you call — the Chat Completions quickstart covers key setup and your first calls.

Looking for the OpenWorker desktop app? Downloads are on its releases page.


Chat Completions — one API across providers

The chat API provides a high-level abstraction for model interactions. It supports all core parameters (temperature, max_tokens, tools, etc.) in a provider-agnostic way, and standardizes request and response structures so you can focus on logic rather than SDK differences.

Model names use the format <provider>:<model-name>; aisuite routes the call to the right provider with the right parameters:

import aisuite as ai
client = ai.Client()

models = ["openai:gpt-4o", "anthropic:claude-3-5-sonnet-20240620"]

messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."},
]

for model in models:
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0.75
    )
    print(response.choices[0].message.content)

→ Quickstart: docs/chat-completions-quickstart.md — install, key setup, local models, and more examples.

Streaming

Pass stream=True to get an iterator of OpenAI-shaped chunks from any supporting provider (OpenAI, Anthropic, Ollama, and OpenAI-compatible endpoints) — the same loop works across all of them:

for chunk in client.chat.completions.create(model=model, messages=messages, stream=True):
    print(chunk.choices[0].delta.content or "", end="", flush=True)

The async variant is await client.chat.completions.acreate(..., stream=True), iterated with async for. Tool calls stream too: schema dicts and callables are passed to the model as usual, and the chunks carry incremental delta.tool_calls fragments for you to assemble and execute (streaming is manual tool calling — it can't be combined with max_turns).


Agents — give models real tools

aisuite turns tool calling into a one-liner: pass plain Python functions and it generates the schemas, executes the calls, and feeds results back to the model.

Tool calling with max_turns

def will_it_rain(location: str, time_of_day: str):
    """Check if it will rain in a location at a given time today.

    Args:
        location (str): Name of the city
        time_of_day (str): Time of the day in HH:MM format.
    """
    return "YES"

client = ai.Client()
response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=[{
        "role": "user",
        "content": "I live in San Francisco. Can you check for weather "
                   "and plan an outdoor picnic for me at 2pm?"
    }],
    tools=[will_it_rain],
    max_turns=2  # Maximum number of back-and-forth tool calls
)
print(response.choices[0].message.content)

With max_turns set, aisuite sends your message, executes any tool calls the model requests, returns the results to the model, and repeats until the conversation completes. response.choices[0].intermediate_messages carries the full tool interaction history if you want to continue the conversation.

Prefer full manual control? Omit max_turns and pass OpenAI-format JSON tool specs — aisuite returns the model's tool-call requests and you run the loop yourself. See examples/tool_calling_abstraction.ipynb for both styles.

The Agents API

For longer-running, structured work there is a first-class Agents API: declare an agent once, run it with a Runner, and attach toolkits — prebuilt, sandboxed tool families for files, git, and shell:

import aisuite as ai
from aisuite import Agent, Runner

agent = Agent(
    name="repo-helper",
    model="anthropic:claude-sonnet-4-6",
    instructions="You are a careful repo assistant. Use your tools to answer from the code.",
    tools=[*ai.toolkits.files(root="."), *ai.toolkits.git(root=".")],
)

result = Runner.run(agent, "What changed in the last commit? Summarize in 3 bullets.")
print(result.final_output)

The Agents API also gives you the pieces a production harness needs:

MCP tools

aisuite natively supports the Model Context Protocol, so any MCP server's tools can be handed to a model without boilerplate (pip install 'aisuite[mcp]'):

client = ai.Client()
response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=[{"role": "user", "content": "List the files in the current directory"}],
    tools=[{
        "type": "mcp",
        "name": "filesystem",
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
    }],
    max_turns=3
)
print(response.choices[0].message.content)

For reusable connections, security filters, and tool prefixing, use the explicit MCPClient.

→ Quickstart: docs/agents-quickstart.md — manual tool handling, the full Agents API, policies, state stores, and MCP in depth.


Extending aisuite: Adding a Provider

New providers can be added by implementing a lightweight adapter. The system uses a naming convention for discovery:

Element Convention
Module file <provider>_provider.py
Class name <Provider>Provider (capitalized)

Example:

# providers/openai_provider.py
class OpenaiProvider(BaseProvider):
    ...

This convention ensures consistency and enables automatic loading of new integrations.


Contributing

Contributions are welcome. Please review the Contributing Guide and join our Discord for discussions.


License

Released under the MIT License — free for commercial and non-commercial use.


aisuite (andrewyng/aisuite)

Searching Database…

16.3K ·GitHub
这是什么?aisuite 是一个轻量级的 Python 库,提供统一的 Chat Completions API,可以对接众多生成式 AI 服务商;它还在此基础上提供 Agents API,支持工具、工具包和 MCP。
它是框架还是只是一个封装库?它是一个 Python 库/SDK,而不是独立应用:它会统一各家服务商的请求和响应格式,因此只需更改一个模型名称字符串就能切换服务商;另外还有一层独立的 Agents API,用于构建调用工具的智能体。
怎么把它加到项目里?通过 pip 安装基础包,再按需安装你打算使用的服务商对应的 SDK 扩展(例如用于 MCP 支持的 'pip install aisuite[mcp]'),然后为这些服务商设置 API 密钥。
开箱即用支持哪些服务商和工具?支持 OpenAI、Anthropic、Google、Mistral、Hugging Face、AWS、Cohere、Ollama、OpenRouter、Requesty 等,还能直接调用任何 MCP 服务器的工具,无需额外的样板代码。
能否同时使用流式输出和多轮工具调用?不能。流式工具调用需要你自己手动拼接并执行增量的 delta.toolcalls 片段,而且它无法与自动的 maxturns 工具调用循环同时使用。
它和 OpenWorker 应用有什么区别,分别适合谁?aisuite 面向用 Python 开发自有大模型应用/智能体的开发者;OpenWorker 则是一款独立的、开箱即用的桌面 AI 协作助手应用(适用于 macOS/Windows),它恰好是基于 aisuite 构建的。
没有云端 API 密钥也能运行吗?可以。aisuite 支持 Ollama 作为服务商,因此你可以在本地运行模型,而无需调用云端 API。
怎样让模型调用我自己的 Python 函数?把普通的 Python 函数作为工具传入,aisuite 会自动生成结构定义、执行调用,并把结果回传给模型;如果设置 'max_turns',还可以让整个循环自动运行。
Agents API 在简单工具调用之外还增加了什么?你只需声明一次智能体,然后用 Runner 运行它;还可以挂载预置的沙箱工具包(用于文件、git 和 shell),设置工具审批策略,持久化或恢复状态(存于内存、文件或 Postgres),并记录产物和追踪信息。
怎样添加对新服务商的支持?创建一个名为 provider.py 的模块,并在其中定义首字母大写的 Provider 类,遵循 aisuite 的命名约定,之后它会被自动发现并加载。
OpenWorker 是什么?OpenWorker 是一款基于 aisuite 构建的桌面 AI 协作助手应用,可以聊天、进行深度研究,并在你的电脑上执行实际任务(如读取文件、连接 Slack/邮件、生成文档);它既可以使用你自己的 API 密钥,也可以通过 Ollama 完全在本地运行。它现在已迁移到独立的代码仓库(andrewyng/openworker)。
Creator
andrewyng
Size
4.3 MB
Stars
16.3K
Age
2y
Commits · 90 Days