ToolBot and AsyncToolBot — Low-Level Design
Created: 2026-03-28
Last updated: 2026-03-28
HLD Link: ../../high-level-design.md
Requirements (EARS)
- toolbot-EARS.md —
ToolBot,AsyncToolBot, tool schemas and chat memory.
Overview
ToolBot performs single-turn tool selection: the model returns function calls, and the bot exposes a list of ChatCompletionMessageToolCall (not a user-facing assistant string). AsyncToolBot uses native acompletion and async_stream_chunks—no asyncio.to_thread around the sync ToolBot.__call__.
Classes
| Class | Module | Base |
|---|---|---|
ToolBot |
llamabot.bot.toolbot |
SimpleBot |
AsyncToolBot |
llamabot.bot.toolbot |
ToolBot |
Tools and memory
- Constructor accepts
toolsandchat_memory(ChatMemorydefault). Whentoolsis empty or missingDEFAULT_TOOLSby name,DEFAULT_TOOLSis prepended (llamabot.components.tools). - Each tool’s
json_schemais passed to LiteLLM astools;name_to_tool_mapmaps function names back to callables.
Message composition
compose_tool_messages:
- Resolves
Callablearguments by calling them (must returnstr). system_prompt+chat_memory.retrieve(first_user_content)whenuser_messagesexist.- Optional
execution_history(last five calls) as aSystemMessageprefix. - Appends user messages.
Call semantics
ToolBot.__call__:make_response+stream_chunks,extract_tool_calls, updateschat_memorywith first user message andAIMessage(content=str(tool_calls)).AsyncToolBot.__call__:make_async_response+async_stream_chunks, then same extraction and memory updates.
Traceability (intent → code)
| EARS ID prefix | Code |
|---|---|
CORE-TOOL-* |
llamabot/bot/toolbot.py |
Related Documents
- High-Level Design
- SimpleBot LLD — shared LiteLLM helpers.
- AgentBot LLD — PocketFlow graph uses
ToolBot/AsyncToolBotinsideDecideNode. - toolbot-EARS