Human-in-the-Loop
Human-in-the-loop (HITL) workflows allow you to maintain control over critical agent actions by requiring human approval before executing certain tools. This is essential for operations that could have significant consequences, such as database modifications, financial transactions, or external API calls with cost implications.
flowchart LR
Agent[Agent] -->|Calls Tool| Check{Requires
Approval?}
Check -->|No| Execute[Execute Tool]
Check -->|Yes| Request[Request Approval]
Request --> Human[Human Review]
Human -->|Approve| Execute
Human -->|Deny| Error[Return Error]
Execute --> Result[Return Result]
Error --> Agent
Result --> Agent
Overview
Section titled “Overview”When a tool is marked as requiring approval, the agent will pause execution and wait for human approval or denial before proceeding. This creates a checkpoint in the agent’s workflow where human judgment can be applied. The approval workflow is designed to be non-blocking and supports both synchronous and streaming message interfaces, making it suitable for interactive applications as well as batch processing systems.
Key Benefits
Section titled “Key Benefits”- Risk Mitigation: Prevent unintended actions in production environments
- Cost Control: Review expensive operations before execution
- Compliance: Ensure human oversight for regulated operations
- Quality Assurance: Validate agent decisions before critical actions
How It Works
Section titled “How It Works”The approval workflow follows a clear sequence of steps that ensures human oversight at critical decision points:
- Tool Configuration: Mark specific tools as requiring approval either globally (default for all agents) or per-agent
- Execution Pause: When the agent attempts to call a protected tool, it immediately pauses and returns an approval request message
- Human Review: The approval request includes the tool name, arguments, and context, allowing you to make an informed decision
- Approval/Denial: Send an approval response to either execute the tool or provide feedback for the agent to adjust its approach
- Continuation: The agent receives the tool result (on approval) or an error message (on denial) and continues processing
Best Practices
Section titled “Best Practices”Following these best practices will help you implement effective human-in-the-loop workflows while maintaining a good user experience and system performance.
1. Selective Tool Marking
Section titled “1. Selective Tool Marking”Not every tool needs human approval. Be strategic about which tools require oversight to avoid workflow bottlenecks while maintaining necessary controls:
Tools that typically require approval:
- Database write operations (INSERT, UPDATE, DELETE)
- External API calls with financial implications
- File system modifications or deletions
- Communication tools (email, SMS, notifications)
- System configuration changes
- Third-party service integrations with rate limits
2. Clear Denial Reasons
Section titled “2. Clear Denial Reasons”When denying a request, your feedback directly influences how the agent adjusts its approach. Provide specific, actionable guidance rather than vague rejections:
# Good: Specific and actionable"reason": "Use read-only query first to verify the data before deletion"
# Bad: Too vague"reason": "Don't do that"The agent will use your denial reason to reformulate its approach, so the more specific you are, the better the agent can adapt.
Setting Up Approval Requirements
Section titled “Setting Up Approval Requirements”There are two methods for configuring tool approval requirements, each suited for different use cases. Choose the approach that best fits your security model and operational needs.
Method 1: Create/Upsert Tool with Default Approval Requirement
Section titled “Method 1: Create/Upsert Tool with Default Approval Requirement”Set approval requirements at the tool level when creating or upserting a tool. This approach ensures consistent security policies across all agents that use the tool. The default_requires_approval flag will be applied to all future agent-tool attachments:
curl --request POST \ --url https://api.letta.com/v1/tools \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "name": "sensitive_operation", "default_requires_approval": true, "json_schema": { "type": "function", "function": { "name": "sensitive_operation", "parameters": {...} } }, "source_code": "def sensitive_operation(...): ..." }'
# All agents using this tool will require approval
curl --request POST \ --url https://api.letta.com/v1/agents \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{"tools": ["sensitive_operation"],// ... other configuration}'# Create a tool that requires approval by defaultapproval_tool = client.tools.upsert_from_function( func=sensitive_operation, default_requires_approval=True,)
# All agents using this tool will require approvalagent = client.agents.create( tools=['sensitive_operation'], # ... other configuration)// Create a tool that requires approval by defaultconst approvalTool = await client.tools.upsert({ name: "sensitive_operation", defaultRequiresApproval: true, jsonSchema: { type: "function", function: { name: "sensitive_operation", parameters: {...} } }, sourceCode: "def sensitive_operation(...): ..."});
// All agents using this tool will require approvalconst agent = await client.agents.create({ tools: ["sensitive_operation"], // ... other configuration});Method 2: Modify Existing Tool with Default Approval Requirement
Section titled “Method 2: Modify Existing Tool with Default Approval Requirement”For an already existing tool, you can modify the tool to set approval requirements on future agent-tool attachments. The default_requires_approval flag will be applied to all future agent-tool attachments:
curl --request PATCH \ --url https://api.letta.com/v1/tools/$TOOL_ID \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "default_requires_approval": true }'
# All agents using this tool will require approval
curl --request POST \ --url https://api.letta.com/v1/agents \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{"tools": ["sensitive_operation"],// ... other configuration}'# Create a tool that requires approval by defaultapproval_tool = client.tools.modify( tool_id=sensitive_operation.id, default_requires_approval=True,)
# All agents using this tool will require approvalagent = client.agents.create( tools=['sensitive_operation'], # ... other configuration)// Create a tool that requires approval by defaultconst approvalTool = await client.tools.modify({ tool_id = sensitive_operation.id, defaultRequiresApproval: true,});
// All agents using this tool will require approvalconst agent = await client.agents.create({ tools: ["sensitive_operation"], // ... other configuration});Method 3: Per-Agent Tool Approval
Section titled “Method 3: Per-Agent Tool Approval”Configure approval requirements for specific agent-tool combinations, allowing fine-grained control over individual agent behaviors. This method is particularly useful for:
- Trusted agents: Remove approval requirements for well-tested, reliable agents
- Progressive autonomy: Gradually reduce approval requirements as agents prove reliable
- Override defaults: Change the approval setting for tools already attached to an agent
Use the following endpoints to modify approval settings for existing agent-tool relationships:
curl --request PATCH \ --url https://api.letta.com/v1/agents/$AGENT_ID/tools/$TOOL_NAME/approval \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "requires_approval": true }'# Modify approval requirement for a specific agentclient.agents.tools.modify_approval( agent_id=agent.id, tool_name="database_write", requires_approval=True,)
# Check current approval settings
tools = client.agents.tools.list(agent_id=agent.id)for tool in tools:print(f"{tool.name}: requires_approval={tool.requires_approval}")// Modify approval requirement for a specific agentawait client.agents.tools.modifyApproval({ agentId: agent.id, toolName: "database_write", requiresApproval: true,});
// Check current approval settingsconst tools = await client.agents.tools.list({ agentId: agent.id,});for (const tool of tools) { console.log(`${tool.name}: requires_approval=${tool.requiresApproval}`);}Handling Approval Requests
Section titled “Handling Approval Requests”Step 1: Agent Requests Approval
Section titled “Step 1: Agent Requests Approval”When the agent attempts to call a tool that requires approval, execution immediately pauses. The agent returns a special approval request message containing:
- Tool name: The specific tool being called
- Arguments: The exact parameters the agent intends to pass
- Tool call ID: A unique identifier for tracking this specific call
- Message ID: The approval request ID needed for your response
- Stop reason: Set to
"requires_approval"to indicate the pause state
This format matches the ToolCallMessage format intentionally, so that we can handle approval requests the same way we handle tool calls. Here’s what an approval request looks like in practice:
curl --request POST \ --url https://api.letta.com/v1/agents/$AGENT_ID/messages \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "messages": [{ "role": "user", "content": "Delete all test data from the database" }] }'
# Response includes approval request
{"messages": [{"message_type": "reasoning_message","reasoning": "I need to delete test data from the database..."},{"message_type": "approval_request_message","id": "message-abc123","tool_call": {"name": "database_write","arguments": "{\"query\": \"DELETE FROM test_data\"}","tool_call_id": "tool-xyz789"}}],"stop_reason": "requires_approval"}response = client.agents.messages.create( agent_id=agent.id, messages=[{ "role": "user", "content": "Delete all test data from the database" }])
# Response includes approval request{ "messages": [ { "message_type": "reasoning_message", "reasoning": "I need to delete test data from the database..." }, { "message_type": "approval_request_message", "id": "message-abc123", "tool_call": { "name": "database_write", "arguments": "{\"query\": \"DELETE FROM test_data\"}", "tool_call_id": "tool-xyz789" } } ], "stop_reason": "requires_approval"}const response = await client.agents.messages.create({ agentId: agent.id, requestBody: { messages: [{ role: "user", content: "Delete all test data from the database" }] }});
// Response includes approval request{ "messages": [ { "message_type": "reasoning_message", "reasoning": "I need to delete test data from the database..." }, { "message_type": "approval_request_message", "id": "message-abc123", "tool_call": { "name": "database_write", "arguments": "{\"query\": \"DELETE FROM test_data\"}", "tool_call_id": "tool-xyz789" } } ], "stop_reason": "requires_approval"}Step 2: Review and Respond
Section titled “Step 2: Review and Respond”Once you receive an approval request, you have two options: approve the tool execution or deny it with guidance. The agent will remain paused until it receives your response.
Approving the Request
Section titled “Approving the Request”To approve a tool call, send an approval message with approve: true and the approval request ID. The agent will immediately execute the tool and continue processing:
curl --request POST \ --url https://api.letta.com/v1/agents/$AGENT_ID/messages \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "messages": [{ "type": "approval", "approvals": [{ "approve": true, "tool_call_id": "tool-xyz789" }] }] }'
# Response continues with tool execution
{"messages": [{"message_type": "tool_return_message","status": "success","tool_return": "Deleted 1,234 test records"},{"message_type": "reasoning_message","reasoning": "I was able to delete the test data. Let me inform the user."},{"message_type": "assistant_message","content": "I've successfully deleted 1,234 test records from the database."}],"stop_reason": "end_turn"}# Approve the tool callresponse = client.agents.messages.create( agent_id=agent.id, messages=[{ "type": "approval", "approvals": [{ "approve": True, "tool_call_id": "tool-xyz789" }] }])
# Response continues with tool execution{ "messages": [ { "message_type": "tool_return_message", "status": "success", "tool_return": "Deleted 1,234 test records" }, { "message_type": "reasoning_message", "reasoning": "I was able to delete the test data. Let me inform the user." }, { "message_type": "assistant_message", "content": "I've successfully deleted 1,234 test records from the database." } ], "stop_reason": "end_turn"}// Approve the tool callconst response = await client.agents.messages.create({ agentId: agent.id, requestBody: { messages: [{ type: "approval", approvals: [{ approve: true, tool_call_id: "tool-xyz789" }] }] }});
// Response continues with tool execution{ "messages": [ { "message_type": "tool_return_message", "status": "success", "tool_return": "Deleted 1,234 test records" }, { "message_type": "reasoning_message", "reasoning": "I was able to delete the test data. Let me inform the user." }, { "message_type": "assistant_message", "content": "I've successfully deleted 1,234 test records from the database." } ], "stop_reason": "end_turn"}Denying with Guidance
Section titled “Denying with Guidance”When denying a tool call, you can provide a reason that helps the agent understand how to adjust its approach. The agent will receive an error response and can use your feedback to reformulate its strategy. This is particularly useful for guiding the agent toward safer or more appropriate actions:
curl --request POST \ --url https://api.letta.com/v1/agents/$AGENT_ID/messages \ --header 'Authorization: Bearer $LETTA_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "messages": [{ "type": "approval", "approvals": [{ "approve": false, "tool_call_id": "tool-xyz789", "reason": "Only delete records older than 30 days, not all test data" }] }] }'
# Response shows agent adjusting based on feedback
{"messages": [{"message_type": "tool_return_message","status": "error","tool_return": "Error: request denied. Reason: Only delete records older than 30 days, not all test data"},{"message_type": "reasoning_message","reasoning": "I need to modify my query to only delete old records..."},{"message_type": "tool_call_message","tool_call": {"name": "database_write","arguments": "{\"query\": \"DELETE FROM test_data WHERE created_at < NOW() - INTERVAL 30 DAY\"}"}}],"stop_reason": "requires_approval"}# Deny with explanationresponse = client.agents.messages.create( agent_id=agent.id, messages=[{ "type": "approval", "approvals": [{ "approve": False, "tool_call_id": "tool-xyz789", "reason": "Only delete records older than 30 days, not all test data" }] }])
# Response shows agent adjusting based on feedback{ "messages": [ { "message_type": "tool_return_message", "status": "error", "tool_return": "Error: request denied. Reason: Only delete records older than 30 days, not all test data" }, { "message_type": "reasoning_message", "reasoning": "I need to modify my query to only delete old records..." }, { "message_type": "tool_call_message", "tool_call": { "name": "database_write", "arguments": "{\"query\": \"DELETE FROM test_data WHERE created_at < NOW() - INTERVAL 30 DAY\"}" } } ], "stop_reason": "requires_approval"}// Deny with explanationconst response = await client.agents.messages.create({ agentId: agent.id, requestBody: { messages: [{ type: "approval", approvals: [{ approve: false, tool_call_id: "tool-xyz789", reason: "Only delete records older than 30 days, not all test data" }] }] }});
// Response shows agent adjusting based on feedback{ "messages": [ { "message_type": "tool_return_message", "status": "error", "tool_return": "Error: request denied. Reason: Only delete records older than 30 days, not all test data" }, { "message_type": "reasoning_message", "reasoning": "I need to modify my query to only delete old records..." }, { "message_type": "tool_call_message", "tool_call": { "name": "database_write", "arguments": "{\"query\": \"DELETE FROM test_data WHERE created_at < NOW() - INTERVAL 30 DAY\"}" } } ], "stop_reason": "requires_approval"}Streaming + Background Mode
Section titled “Streaming + Background Mode”For streaming clients using background mode, approvals are best handled via agents.messages.createStream(..., background: true). The approval response may include the tool_return_message on the approval stream itself, and follow‑up reasoning/assistant messages can be read by resuming that stream’s run_id.
# Approve in background after receiving approval_request_messagecurl --request POST --url https://api.letta.com/v1/agents/$AGENT_ID/messages/stream --header 'Content-Type: application/json' --data '{ "messages": [{"type": "approval", "approve": true, "approval_request_id": "message-abc"}], "stream_tokens": true, "background": true}'
# Example approval stream output (tool result arrives here):
data: {"run_id":"run-new","seq_id":0,"message_type":"tool_return_message","status":"success","tool_return":"..."}
# Continue by resuming the approval stream's run
curl --request GET --url https://api.letta.com/v1/runs/$RUN_ID/stream --header 'Accept: text/event-stream' --data '{"starting_after": 0}'# Receive an approval_request_message, then approve in backgroundapprove = client.agents.messages.create_stream( agent_id=agent.id, messages=[{"type": "approval", "approvals": [{"approve": True, "tool_call_id": "tool-xyz789"}]}], stream_tokens=True, background=True,)
run_id = Nonelast_seq = 0for chunk in approve: if hasattr(chunk, "run_id") and hasattr(chunk, "seq_id"): run_id = chunk.run_id last_seq = chunk.seq_id if getattr(chunk, "message_type", None) == "tool_return_message": # Tool result arrives here on the approval stream break
# Continue consuming output by resuming the background runif run_id: for chunk in client.runs.stream(run_id, starting_after=last_seq): print(chunk)// Receive an approval_request_message, then approve in backgroundconst approve = await client.agents.messages.createStream({ agentId: agent.id, requestBody: { messages: [ { type: "approval", approvals: [{ approve: true, tool_call_id: "tool-xyz789" }], }, ], streamTokens: true, background: true, },});
let runId: string | null = null;let lastSeq = 0;for await (const chunk of approve) { if (chunk.run_id && chunk.seq_id) { runId = chunk.run_id; lastSeq = chunk.seq_id; } if (chunk.message_type === "tool_return_message") { // Tool result arrives here on the approval stream break; }}
// Continue consuming output by resuming the background runif (runId) { const resume = await client.runs.stream(runId, { startingAfter: lastSeq }); for await (const chunk of resume) { console.log(chunk); }}See background mode for resumption patterns.
IDs and UI Triggers
Section titled “IDs and UI Triggers”- approval_request_id: This field is now deprecated, but it is still used for backwards compatibility. Used
approval_request_message.id. - tool_call_id: Always send approvals/denials using the
tool_call_idfrom theApprovalRequestMessage. - UI trigger: Open the approval UI on
approval_request_messageonly; do not derive UI fromstop_reason.