Skip to content
cccskills
FreePublished on GitHub

ai-python-custom-provider

Use for implementing custom providers in AI SDK for Python.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md2.8 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

ai-python-custom-provider

Providers emit model events. They do not run Python tools. ai.stream collects events into a Message. ai.Agent adds tool execution, hooks, and replay.

Minimal shape:

from collections.abc import AsyncGenerator, Sequence
from typing import Any, Literal

import pydantic
import ai


class MyProtocol(ai.ProviderProtocol[Any]):
    protocol_class_id: Literal["my_protocol"] = "my_protocol"

    def stream(
        self,
        client: Any,
        model: ai.Model,
        messages: list[ai.messages.Message],
        *,
        tools: Sequence[ai.tools.Tool] | None = None,
        output_type: type[pydantic.BaseModel] | None = None,
        params: ai.InferenceRequestParams | None = None,
        provider: str,
    ) -> AsyncGenerator[ai.events.Event]:
        return self._stream(client, model, messages, tools=tools)

    async def _stream(
        self,
        client: Any,
        model: ai.Model,
        messages: list[ai.messages.Message],
        *,
        tools: Sequence[ai.tools.Tool] | None,
    ) -> AsyncGenerator[ai.events.Event]:
        yield ai.events.StreamStart()
        yield ai.events.TextStart(block_id="text")
        yield ai.events.TextDelta(block_id="text", chunk="Hello")
        yield ai.events.TextEnd(block_id="text")
        yield ai.events.StreamEnd()


class MyProvider(ai.Provider[Any]):
    provider_class_id: Literal["my_provider"] = "my_provider"
    name: str = "my"
    default_base_url: str = "https://example.invalid"

    def __init__(self, *, client: Any) -> None:
        super().__init__()
        self._set_client(client)

    def default_protocol(self) -> ai.ProviderProtocol[Any]:
        return MyProtocol()

    async def list_models(self) -> list[str]:
        return ["my-model"]

    async def probe(self, model: ai.Model) -> None:
        return None


model = ai.Model(id="my-model", provider=MyProvider(client=client))

For Python tool calls, emit ToolStart, ToolDelta, and ToolEnd:

yield ai.events.ToolStart(tool_call_id=tcid, tool_name=name)
yield ai.events.ToolDelta(tool_call_id=tcid, chunk=args_json)
yield ai.events.ToolEnd(
    tool_call_id=tcid,
    tool_call=ai.messages.DUMMY_TOOL_CALL,
)

The stream collector fills event.tool_call with the aggregated tool call. Then Agent resolves and runs the tool.

If the provider runs its own built-in tool, emit BuiltinToolStart, BuiltinToolDelta, BuiltinToolEnd, and BuiltinToolResult instead.

Do not implement a custom provider for normal app configuration. Prefer ai.get_provider(...), ai.get_model(...), or a protocol override unless you are adding a new upstream API adapter.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Use for AI SDK for Python basics. Configure a model, make messages, stream, declare tools, build a basic agent.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

Use when building custom agent loops. Modify tool dispatch, history management, hooks, control flow.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

Use when adding durable execution to AI SDK for Python, building durable agent loops, or serializing messages across workflow steps.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

Use when building serverless AI SDK for Python endpoints, handling hook approvals, deferring hooks, or resuming runs across requests.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

Use for AI SDK for Python async-generator tools, streaming tool output, subagent tools, PartialToolCallResult events, and custom tool aggregation.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

Use for the subagent-as-a-tool pattern.

The English summary is being prepared. Showing the original description.

vercel-labs/seal8Updated Oct 7, 2026

See all skills by vercel-labs

Report a problem with this skill