Skip to main content

Overview

StateGraph is perfect for building AI agents - systems that can reason, use tools, and make decisions autonomously. An agent workflow typically follows this pattern:
This is known as the ReAct pattern (Reasoning + Acting).

Basic Agent Pattern

Here’s the simplest agent structure:
Automatic Tool Execution: When you use model.bind_tools(), Upsonic automatically executes tool calls and feeds results back to the LLM. The final response is already processed.

Agentic Loop with Conditional Exit

Create agents that loop until they complete the task:
Always set max_iterations and recursion_limit to prevent infinite loops in agentic workflows.

Best Practices

1. Clear System Prompts

2. Limit Tool Sets

Only provide relevant tools:

3. Set Guardrails

Protect against runaway agents:

Next Steps