Tools and Sub-agents¶
A tool is any callable an agent may use. Tools may include:
- Simple functions (e.g., time, file IO, reflection)
- Sub-agents (agents with their own system instructions, state access, and toolsets)
Tools are ordinary async Python functions (or Agent instances) that Pydantic AI can call via function calling. They usually accept a RunContext[RuntimeState] when they need access to the shared plan and document store.
Core Built-in Tools (pydantask.tools.default_tools)¶
think_tool¶
A lightweight reflection tool:
- Signature:
async def think_tool(reflection: str) -> str - Purpose: Let agents write down and “externalize” strategic thoughts.
- When to use:
- After receiving search results (summarize findings and gaps)
- Before deciding next steps (do I have enough to answer?)
It returns a simple confirmation string and does not modify state.
File System and Document Tools¶
These tools work within a workspace directory (pydantask/tools/tmp_files) and also update RuntimeState.document_store so agents can find files by logical name.
write_to_file_system¶
- Signature:
async def write_to_file_system(ctx: RunContext[RuntimeState], file_name: str, content: str, overwrite: bool = False) -> str- Behavior:
- Writes
contenttotmp_files/<file_name>. - Appends by default; set
overwrite=Trueto replace the file. - Registers
file_nameinctx.deps.document_storeso it can be listed and read later.
read_from_file_system¶
- Signature:
async def read_from_file_system(ctx: RunContext[RuntimeState], file_name: str) -> str- Behavior:
- Resolves
file_nameviactx.deps.document_store(logical name → path) and reads the file fromtmp_files. - Returns an informative message if the file does not exist.
delete_from_file_system¶
- Signature:
async def delete_from_file_system(path: str) -> str- Behavior:
- Attempts to delete
tmp_files/<path>; ignores missing files.
list_documents¶
- Signature:
async def list_documents(ctx: RunContext[RuntimeState]) -> str- Behavior:
- Lists logical document names and their resolved filesystem paths from
document_store.
Task and Context Tools¶
These tools operate on RuntimeState.plan and task‑scoped context files.
get_current_datetime¶
- Signature:
async def get_current_datetime() -> str - Behavior:
- Returns the current timestamp as an ISO‑8601 string.
- Used by Planner/Supervisor/Researcher for time‑aware reasoning.
list_completed_tasks¶
- Signature:
async def list_completed_tasks(ctx: RunContext[RuntimeState]) -> str - Behavior:
- Walks
ctx.deps.planand returns a human‑readable list of tasks whosestatus == TaskStatus.COMPLETEDwith brief summaries.
save_task_context¶
- Signature:
async def save_task_context(ctx: RunContext[RuntimeState], task_id: int, content: str, kind: str = "notes", overwrite: bool = False) -> str- Behavior:
- Writes
contentto a canonical filetask-{task_id}-{kind}.mdintmp_filesviawrite_to_file_system. - Useful for per‑task notes (
kind="notes"), research ("research"), or final reports ("final").
read_task_context¶
- Signature:
async def read_task_context(ctx: RunContext[RuntimeState], task_id: int, kind: str = "notes") -> str- Behavior:
- Reads the canonical file
task-{task_id}-{kind}.mdviaread_from_file_system.
get_task_result¶
- Signature:
async def get_task_result(ctx: RunContext[RuntimeState], task_id: int) -> str- Behavior:
- Looks up
task_idinctx.deps.planand returns theTaskResultas pretty‑printed JSON, or a diagnostic message if none exists.
append_scratch_note¶
- Signature:
async def append_scratch_note(ctx: RunContext[RuntimeState], task_id: int, note: str) -> str- Behavior:
- Appends
noteto an in‑memory scratchpad entryscratch_task_{task_id}inctx.deps.document_store. - Intended for lightweight, transient “running memory” during a task, not final reports.
ask_user (optional interactive tool)¶
- Signature:
async def ask_user(ctx: RunContext[RuntimeState], question_for_user: str) -> str- Behavior:
- Prompts on stdin and returns the user’s answer.
- This is synchronous/interactive and most useful in CLI environments.
Registering Tools and Sub‑agents¶
Built‑in agents are constructed inside DeepAgent with specific tool lists (see
pydantask/agents/agent.py). In the current implementation:
- The research agent capability (
research_agent) has access to: tavily_search_toolwhenTAVILY_API_KEYis set, otherwise a DuckDuckGo‑based search tool.think_toolappend_scratch_noteread_scratch_notes-
get_current_datetime -
The producer agent capability (
producer_agent) has access to: list_completed_tasksget_task_result-
think_tool -
The general worker agent capability (
worker_agent) has access to: list_completed_tasksget_task_resultthink_toolappend_scratch_note,read_scratch_notes-
get_current_datetime -
The supervisor agent (top-level orchestrator agent) can call DeepAgent methods as tools:
add_task,cancel_task,patch_taskupdate_task_statusview_qa_report- plus
get_current_datetimeandthink_tool
Additional tools or sub‑agents can be registered by creating CapabilityDescription
instances and passing them via the sub_agents parameter to
DeepAgent.__init__. Those capabilities then become available to the
supervisor via RuntimeState.agent_registry.