Skip to main content

The AI Toolkit for Python

Project description

ai

[!WARNING] This framework is experimental. It is not stable and is not guaranteed to be maintained in the future. For evaluation purposes only.

Python toolkit for building model-powered apps and agent loops.

Install

uv add vercel-ai-sdk
import ai

Quick Start

import asyncio

import ai


@ai.tool
async def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 72F in {city}"


async def main() -> None:
    model = ai.model("ai-gateway", "anthropic/claude-sonnet-4")
    agent = ai.agent(tools=[get_weather])

    messages = [
        ai.system_message("You are a helpful weather assistant."),
        ai.user_message("What's the weather in Tokyo?"),
    ]

    async for msg in agent.run(model, messages):
        if msg.text_delta:
            print(msg.text_delta, end="", flush=True)
    print()


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

API Surface

Models

ai.model(provider, model_id)    model metadata (providers: ai-gateway, anthropic, openai)
ai.stream(model, messages, ...) streaming generation (supports tools=, output_type=, client=)
ai.generate(model, messages)    non-streaming / image / video generation
ai.check_connection(model)      verify credentials and model availability
ai.Client(base_url=, api_key=)  explicit client when you need a custom endpoint

Agents

ai.agent(tools=[...])           agent with tool loop
ai.tool                         decorator: schema gen + validation + execution
ai.hook(name, payload=, ...)    suspension point; resolve with ai.resolve_hook(...)
ai.resolve_hook(name, value)    resolve a pending hook from outside the loop
ai.cancel_hook(name)            cancel a pending hook
ai.yield_from(...)              forward nested agent / streaming tool output

Messages

ai.system_message  ai.user_message  ai.assistant_message  ai.tool_message
ai.tool_result     ai.file_part     ai.thinking

Integrations

ai.mcp.get_http_tools(url, ...) expose an MCP server as tools
ai.telemetry.enable/disable()   OpenTelemetry-style event hooks
ai.ai_sdk_ui                    AI SDK UI streaming adapter

Custom Agent Loops

Override the default loop when you need approval gates, routing, or custom orchestration:

@agent.loop
async def custom(context: ai.Context):
    while True:
        s = await ai.models.stream(
            context.model, context.messages, tools=context.tools
        )
        async for msg in s:
            yield msg

        tool_calls = context.resolve(s.tool_calls)
        if not tool_calls:
            return

        results = [await tc() for tc in tool_calls]
        yield ai.tool_message(*results)

Examples

Small focused samples live in examples/samples/. End-to-end demos:

  • examples/fastapi-vite/ -- FastAPI backend + Vite frontend with hook-based tool approval
  • examples/multiagent-textual/ -- Textual TUI with parallel agents and interactive hook resolution
  • examples/temporal-durable/ -- durable execution patterns with Temporal

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

vercel_ai_sdk-0.0.1.dev9.tar.gz (59.3 kB view details)

Uploaded Source

Built Distribution

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

vercel_ai_sdk-0.0.1.dev9-py3-none-any.whl (79.4 kB view details)

Uploaded Python 3

File details

Details for the file vercel_ai_sdk-0.0.1.dev9.tar.gz.

File metadata

  • Download URL: vercel_ai_sdk-0.0.1.dev9.tar.gz
  • Upload date:
  • Size: 59.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for vercel_ai_sdk-0.0.1.dev9.tar.gz
Algorithm Hash digest
SHA256 38b2f71764afb3418feddd4790cc5b9f5a48398e7de59908d0c097b7161654f7
MD5 91b84fded737b96932d4a0b2408c61fd
BLAKE2b-256 8f8fdb0ae993fd806c52528cccd20509039e9b5a37f1b080b891e346217d5e5e

See more details on using hashes here.

File details

Details for the file vercel_ai_sdk-0.0.1.dev9-py3-none-any.whl.

File metadata

  • Download URL: vercel_ai_sdk-0.0.1.dev9-py3-none-any.whl
  • Upload date:
  • Size: 79.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for vercel_ai_sdk-0.0.1.dev9-py3-none-any.whl
Algorithm Hash digest
SHA256 05d992e8f572bb0143852e2adeaded9ecde04e77ba3d5ad42ebaec5142d5af5b
MD5 1922204cf777c19a9dbda310870562bc
BLAKE2b-256 b2f0aa03a2be79cb0f770fa3a3f5b736eb6313268502b99661404fc77a8c7b47

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