Skip to main content

VibeAgent / VibeAgent(中文)

VibeAgent 是一个轻量的 AI Agent SDK,核心目标是用尽量少的抽象把「对话 → 推理 → 工具调用 → 工具结果回传 → 继续推理」这条链路跑通,并保持与 OpenAI 协议的兼容性(chat.completions / tools)。

安装

pip install vibe-agent

快速开始

1) 初始化推理层(Inferrer)

你需要显式传入 server_base_url 与 API Key(或通过环境变量提供)。

  • API Key 优先级:server_apikey 参数 > 环境变量 INFER_API_KEY
  • 如果两者都缺失,会抛出异常
import asyncio
from vibe_agent.infer_layer import Inferrer

async def main():
    inferrer = Inferrer(
        server_base_url="https://openrouter.ai/api/v1",
        server_apikey="YOUR_API_KEY"
    )

    resp = await inferrer.run(
        model="google/gemini-3-flash-preview",
        messages=[{"role": "user", "content": "你好"}],
    )
    print(resp.choices[0].message.content)

asyncio.run(main())

2) 使用 ChatConfig 管理推理参数

ChatConfig 用于集中存储推理参数(messages、tools、temperature 等),并允许通过 extra_params 透传符合 OpenAI 协议的自定义参数。

from vibe_agent.infer_layer import ChatConfig

config = ChatConfig(
    model="google/gemini-3-flash-preview",
    messages=[{"role": "user", "content": "总结一下这段话"}],
    temperature=0.2,
    extra_params={"top_k": 40},
)

3) 使用对话管理层(DialogueManager)自动执行工具

DialogueManager 会在模型返回 tool_calls 时,自动调用本地工具函数,并把工具结果按 OpenAI 协议(role=tool)回传给模型,直至模型不再请求工具或达到 max_turns。

import asyncio
from vibe_agent.infer_layer import Inferrer
from vibe_agent.dialogue_layer import DialogueManager

def get_weather(city: str):
    return f"{city} weather is sunny."

async def main():
    inferrer = Inferrer(
        server_base_url="https://openrouter.ai/api/v1",
        server_apikey="YOUR_API_KEY"
    )
    dm = DialogueManager(inferrer=inferrer, tools_map={"get_weather": get_weather})

    tools = [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get weather information for a city.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {"type": "string", "description": "City name"}
                    },
                    "required": ["city"]
                }
            }
        }
    ]

    resp = await dm.chat(
        messages=[{"role": "user", "content": "北京天气怎么样?"}],
        model="google/gemini-3-flash-preview",
        tools=tools
    )
    print(resp.choices[0].message.content)

asyncio.run(main())

4) 自动把 Python 函数转换为 tools schema(并带本地缓存)

如果你不想手写 tools schema,可以用 register_tools():

  • 输入:若干 Python callable
  • 输出:自动生成并注入符合 OpenAI SDK 的 tools 列表
  • 缓存:如果函数源码未变化,会复用本地缓存(默认 .vibe_tool_cache.json)避免重复消耗推理成本
import asyncio
from vibe_agent.infer_layer import Inferrer
from vibe_agent.dialogue_layer import DialogueManager

def calculate_sum(a: int, b: int):
    \"\"\"Calculate sum of two integers.\"\"\"
    return a + b

async def main():
    inferrer = Inferrer(
        server_base_url="https://openrouter.ai/api/v1",
        server_apikey="YOUR_API_KEY"
    )
    dm = DialogueManager(inferrer=inferrer)

    await dm.register_tools([calculate_sum], model="google/gemini-3-flash-preview")

    resp = await dm.chat(
        messages=[{"role": "user", "content": "帮我算 123 + 456"}],
        model="google/gemini-3-flash-preview",
    )
    print(resp.choices[0].message.content)

asyncio.run(main())

环境变量

  • INFER_API_KEY: 当 server_apikey 未传入时使用

安全提示

  • 不要把 API Key 写进代码或提交到 Git
  • .trae/rules/pypi.md 用于本地保存 PyPI Token,必须保持不入库

VibeAgent (English)

VibeAgent is a lightweight AI Agent SDK that keeps the core loop minimal: conversation → inference → tool calls → tool execution → tool result back to the model. It stays compatible with the OpenAI-style chat.completions interface and tools schema.

Installation

pip install vibe-agent

Quick Start

1) Initialize Inferrer

You must pass server_base_url explicitly, and provide an API key via argument or environment.

  • API key priority: server_apikey argument > INFER_API_KEY env var
  • If both are missing, an exception is raised
import asyncio
from vibe_agent.infer_layer import Inferrer

async def main():
    inferrer = Inferrer(
        server_base_url="https://openrouter.ai/api/v1",
        server_apikey="YOUR_API_KEY"
    )

    resp = await inferrer.run(
        model="google/gemini-3-flash-preview",
        messages=[{"role": "user", "content": "Hello"}],
    )
    print(resp.choices[0].message.content)

asyncio.run(main())

2) Manage parameters with ChatConfig

ChatConfig stores inference parameters (messages/tools/temperature/etc.) and supports passing extra OpenAI-compatible fields via extra_params.

3) Use DialogueManager for tool execution

DialogueManager detects tool_calls in model responses, executes local tool callables, and appends OpenAI-style tool messages back to the conversation until no more tool calls are requested (or max_turns is reached).

4) Auto-generate tools schema from Python callables (with local caching)

Use register_tools() to let the model generate OpenAI tools schema from Python functions. Results are cached by function source hash in .vibe_tool_cache.json (default).

Metadata

Release files for vibe-agent 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vibe-agent 0.0.3
File Size Uploaded
vibe_agent-0.0.3.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vibe-agent 0.0.3
File Interpreter ABI Platform
vibe_agent-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / vibe_agent-0.0.3.tar.gz

Download URL vibe_agent-0.0.3.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
13b5a779237135412ca59141c735eddf137552b7136c9c417e90cf603f03003b
BLAKE2b-256 checksum
How to use checksums
392edf0c7a2d18524b1ecdd4ace5a87b755de9defbcbc1d6cec0f75f45746aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / vibe_agent-0.0.3-py3-none-any.whl

Download URL vibe_agent-0.0.3-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0851884e05fa8bfa6f996b0760b42d7d76bf503fc9151f0b1cd6c5cf8bb36f9
BLAKE2b-256 checksum
How to use checksums
cc776f91c37c7323e81bec45897e387bf02ad3d5d1bb347a2dd2dd79ceb36099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page