How venkataramana2005/react-agent works
Purpose and Runtime Entry Points
This repository implements a stateful, single-agent ReAct engine: it accepts chat requests, reasons with an LLM, invokes controlled tools, pauses risky actions for human review, and streams progress/results to clients. The service entry point is FastAPI in api/main.py; request/event contracts are in api/schemas.py. Container deployment is defined by Dockerfile and compose.yaml.
API and Streaming Boundary
The API exposes chat streaming and approval-resume flows. It validates inbound request models, starts or resumes an agent execution, and emits Server-Sent Events for reasoning/tool/final-response lifecycle events. This is the external boundary between clients and the internal graph.
• api/main.py
• api/schemas.py
Stateful Agent Graph
LangGraph coordinates the execution state machine. The agent node calls the configured Groq-hosted Llama model, incorporates messages and retrieved context, and produces either a final answer or tool calls. Routing selects the next graph stage—continued reasoning, tool execution, approval, or completion—and workflow construction owns graph assembly/checkpoint behavior.
• agent_loop/workflow.py
• agent_loop/agent_node.py
• agent_loop/routing.py
Guardrail Pipeline
Input validation is performed before model execution to reject or sanitize unsafe prompts, sensitive data, and abusive traffic. Output validation is a separate terminal boundary before results are delivered to the client. These stages protect both external-model calls and client-facing responses.
• guardrails/input_guardrails.py
• guardrails/output_guardrails.py
Tool Execution and Isolation
The dispatcher is the agent-to-capability boundary: it resolves tool names, validates arguments, executes calls, and converts results/errors into observations for another ReAct turn. Available capabilities include web search, retrieval-augmented knowledge lookup, sandboxed code execution, and workspace-constrained file operations.
• tools/dispatcher.py
• tools/web_search.py
• tools/code_interpreter.py
• tools/rag_retriever.py
• tools/file_ops.py
External dependencies include Tavily for web search, a vector-store-backed retrieval/memory implementation, and potentially an isolated execution environment for Python. File operations should remain bounded by workspace/.
Memory and Persistence Flow
Short-term memory retains active session turns and intermediate tool observations for graph execution. Long-term memory persists/retrieves user-scoped semantic context via a vector-store abstraction; retrieved memories feed future agent turns, while completed interactions can be consolidated back into persistent memory. Local persistent-data placeholders are under data/memory_store/.
• memory_layer/short_term.py
• memory_layer/long_term.py
• data/memory_store/.gitkeep
Human Approval Control Plane
High-risk tool calls—such as code execution or writes—are intercepted before dispatch. The approval layer creates an interrupt/pending task, and the API approval route resumes or rejects the paused graph using the task/session state. This separates autonomous low-risk reads/searches from operations requiring explicit authorization.
• hitl/approval.py
• agent_loop/workflow.py
• api/main.py
Configuration and Observability
Runtime settings centralize model and provider credentials/configuration, including Groq inference, Google embedding services, Tavily, and LangSmith tracing. LangSmith is the primary observability service for model/tool traces, latency, and audit-relevant execution events.
• settings.py
• requirements.txt
Main entry points: workflow.py LangGraph workflow · dispatcher.py Tool dispatcher · main.py FastAPI streaming API · agent_node.py ReAct agent node
Components 19
API Boundary
- FastAPI streaming API · Starts, resumes, and streams agent runs as SSE.
api/main.py - Request/event contracts
api/schemas.py
Agent Execution
- LangGraph workflow · Assembles execution, routing, interrupts, and checkpoints.
agent_loop/workflow.py - ReAct agent node · Calls the configured Groq-hosted Llama model.
agent_loop/agent_node.py - Graph routing
agent_loop/routing.py
Controlled Capabilities
- Tool dispatcher · Validates, executes, and returns tool observations.
tools/dispatcher.py - Web search
tools/web_search.py - Knowledge retrieval
tools/rag_retriever.py - Sandboxed Python
tools/code_interpreter.py - Workspace file operations · Operations remain bounded by workspace/.
tools/file_ops.py
Memory & Persistence
- Short-term session memory · Retains turns and tool observations during a run.
memory_layer/short_term.py - Long-term semantic memory · Retrieves and consolidates user-scoped context.
memory_layer/long_term.py - Local memory store
data/memory_store/.gitkeep
Safety & Operations
- Input guardrails
guardrails/input_guardrails.py - Human approval · Pauses high-risk tool calls pending a decision.
hitl/approval.py - Output guardrails
guardrails/output_guardrails.py - LangSmith tracing · Captures model, tool, latency, and audit traces.
Other components
- Chat client
- Groq Llama inference
Connections 26
- Chat client → FastAPI streaming API: chat / approval resume
- FastAPI streaming API → Request/event contracts: validates and serializes
- FastAPI streaming API → Input guardrails: screens request
- Input guardrails → LangGraph workflow: approved input
- FastAPI streaming API → LangGraph workflow: start or resume run
- LangGraph workflow → ReAct agent node: reasoning turn
- ReAct agent node → Groq Llama inference: inference
- Short-term session memory → ReAct agent node: session context
- Long-term semantic memory → ReAct agent node: retrieved context
- ReAct agent node → Graph routing: answer or tool calls
- Graph routing → Tool dispatcher: low-risk tool call
- Graph routing → Human approval: high-risk tool call
- Human approval → LangGraph workflow: approved or rejected resume
- Tool dispatcher → Web search: search
- Tool dispatcher → Knowledge retrieval: retrieve
- Tool dispatcher → Sandboxed Python: execute
- Tool dispatcher → Workspace file operations: read/write
- Tool dispatcher → LangGraph workflow: observation
- LangGraph workflow → Short-term session memory: checkpoints and observations
- Long-term semantic memory → Local memory store: persists vectors
- LangGraph workflow → Long-term semantic memory: consolidates completed interaction
- Graph routing → Output guardrails: final response
- Output guardrails → FastAPI streaming API: safe SSE result
- FastAPI streaming API → Chat client: SSE lifecycle events
- LangGraph workflow → LangSmith tracing: execution traces
- Tool dispatcher → LangSmith tracing: tool traces