Skip to main content

chatchat — Agent Framework

Python agent framework with LLM tool calling, multi-agent orchestration, and a scheduler-based event-driven architecture.

Install

pip install chatchat

Quick Start

Single Agent

import asyncio
from chatchat.agent import AgentConfig, create_agent
from chatchat.tool import tool

@tool(
    name='get_weather', description='get weather for a city',
    parameters={
        'type': 'object',
        'properties': {
            'city': {'type': 'string', 'description': 'the city name, e.g., Shanghai'},
        },
        'required': ['city'],
    },
)
def get_weather(city):
    return f'{city} is Sunny.'

agent = create_agent(AgentConfig(
    name='assistant',
    provider='agnes', model='agnes-2.5-flash',
    instruction='You are a helpful assistant.',
    tools=[get_weather],
))

async def main():
    result = await agent.chat('How is the weather in Shanghai?')
    print(result)
    await agent.stop()

asyncio.run(main())

Multi-Agent Team

Teams inherit from Agent and carry management tools (create_agent, create_team, send_message, task_stop). Sub-agents are created on demand by the leader and communicate through the scheduler via runtime.request / reply.

import asyncio
from chatchat.team import TeamConfig, create_team
from chatchat.runtime import get_runtime, make_id

team = create_team(TeamConfig(
    name='lead',
    provider='agnes', model='agnes-2.5-flash',
    instruction='You are a tech lead. Use create_agent to delegate tasks to sub-agents.',
    agent_tools=[],
))

async def main():
    reply = await get_runtime().request(
        source=make_id(), target_id=team.id,
        topic=f'entity:team:{team.id}:text',
        data='write a tutorial to output.md', timeout=300,
    )
    print(reply)
    await team.stop()
    get_runtime().shutdown()

asyncio.run(main())

Tools

Tools are registered with the @tool decorator. They run inside the AgentLoop; the LLM's tool calls are accumulated by index, executed, and fed back for further turns.

from chatchat.tool import tool

@tool(
    name='add', description='add two numbers',
    parameters={
        'type': 'object',
        'properties': {
            'a': {'type': 'integer'},
            'b': {'type': 'integer'},
        },
        'required': ['a', 'b'],
    },
)
def add(a, b):
    return a + b

Skills

Skills are directories containing a SKILL.md. Their instruction block is injected into the agent's system prompt.

agent = create_agent(AgentConfig(
    name='skilled',
    provider='agnes', model='agnes-2.5-flash',
    instruction='You are a helpful assistant.',
    skills=['/path/to/skill_dir'],
))

Architecture

  • Scheduler / Runtime — core message router. Agent-to-Agent and delegation communication go through the scheduler using topic-based addressing (entity:<kind>:<id>:<type>), with blocking request/reply and fire-and-forget publish. Calling agent.chat() runs the agent loop directly in the caller.
  • Agent — wraps an LLM client, a tool set, and the AgentLoop (streaming, tool-call accumulation, lifecycle hooks start/step/end/error).
  • Team — an Agent with management tools; leader_tools configure the leader's tools, agent_tools configure tools given to created sub-agents.
  • Client / providers — async streaming LLM clients (aiohttp) for agnes, deepseek, openrouter, google, alibaba, baidu, zhipu, tencent, xunfei, etc.

Observe runtime activity with get_runtime().enable_logging('agent', 'team', 'client', 'tool'). Lifecycle topics: lifecycle:agent:start/step/end/error, lifecycle:client:start/step/end/error, lifecycle:tool:start/step/end/error.

Configuration

chatchat config --list
chatchat config <provider>.api_key=YOUR_API_KEY
chatchat run --provider agnes --model agnes-2.5-flash --thinking

Rate limits can be set programmatically:

from chatchat.rate_limiter import set_rate_limits
set_rate_limits([
    {'provider': 'agnes', 'rpm': 20, 'tpm': 0, 'max_concurrent': 0},
])

Examples

See examples for complete usage:

  • agent.py — Interactive terminal chat with tool calling
  • team.py — Leader team delegating tasks to dynamically created sub-agents
  • tool.py — Raw client with tool calling
  • client.py — Raw LLM client streaming usage
  • state.py — Agent state serialization and restoration
  • interact.py — Interactive tool confirmation
  • progress.py — Streaming progress with custom tools

Sponsor

公众号
AliPay.png
AliPay WeChatPay
AliPay.png WeChatPay.png

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatchat-0.5.0.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

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

chatchat-0.5.0-py3-none-any.whl (40.4 kB view details)

Uploaded Python 3

File details

Details for the file chatchat-0.5.0.tar.gz.

File metadata

  • Download URL: chatchat-0.5.0.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chatchat-0.5.0.tar.gz
Algorithm Hash digest
SHA256 bdfa1ffa817da63e15db80125f3619c3b382eab872b01c09201eacabd4ace050
MD5 c12531741f6418a2eedb43c0a523a4f9
BLAKE2b-256 828d9e7f76b634fb667bfb7b3f29fd49b15ba8f1755c9e8c906af3379fd2e721

See more details on using hashes here.

File details

Details for the file chatchat-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: chatchat-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 40.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chatchat-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48d7297d9630d542d2ad59d004affeaf8b8bce1421c7e43315a41f21aa53f2ee
MD5 bc00cf01c8d80df29d3590c821969296
BLAKE2b-256 ea5db5484347c993b3b7ebf077ec63ebc3517f81daa3bf8d4e39f3d96da8426a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.6

2 files

0.4.5

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page