跳到正文
cccskills
免费在 GitHub 公开

ai-python-custom-loop

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

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md1.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

ai-python-custom-loop

Keep the default shape unless you must change control flow:

class MyAgent(ai.Agent):
    async def loop(self, context: ai.Context):
        while context.keep_running():
            async with (
                ai.stream(context=context) as stream,
                ai.ToolRunner() as runner,
            ):
                async for event in ai.util.merge(stream, runner.events()):
                    yield event

                    if isinstance(event, ai.events.ToolEnd):
                        runner.schedule(context.resolve(event.tool_call))

                context.add(stream.message)
                context.add(runner.get_tool_message())

Rules:

  • Call context.keep_running() at the top of each turn.
  • Use ai.stream(context=context) so model, messages, tools, output type, and params stay together.
  • Yield events from the loop. Agent.run hides replay events from callers.
  • On ToolEnd, use context.resolve(event.tool_call). It handles validation, approval gates, and cached replay results.
  • Do not call tool.fn directly unless you also handle validation, approvals, and cached results.
  • Schedule resolved calls with ToolRunner.schedule(...).
  • ToolRunner.schedule(...) also accepts a zero-arg async callable that returns ai.events.ToolCallResult.
  • If you make a result yourself, use runner.add_result(ai.tool_result(...)).
  • Add stream.message, then runner.get_tool_message(). context.add(...) skips replay messages.
  • Every tool call must get one tool result.
  • For hooks, let context.resolve(...) build the gated call. Use ai-python-serverless-execution for request boundaries.
  • For durable calls, keep this shape and wrap only model or tool I/O. Use ai-python-durable-execution.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

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

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

Use for implementing custom providers in AI SDK for Python.

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

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

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

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

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

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

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

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

中文简介正在准备中。当前显示原文说明。

vercel-labs/seal82026年10月7日 更新

查看 vercel-labs 的全部技能

报告此技能的问题