Skip to content
  • Auto
  • Light
  • Dark
DiscordForumGitHubSign up
Building on the Letta API
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

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

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.

  • 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

The approval workflow follows a clear sequence of steps that ensures human oversight at critical decision points:

  1. Tool Configuration: Mark specific tools as requiring approval either globally (default for all agents) or per-agent
  2. Execution Pause: When the agent attempts to call a protected tool, it immediately pauses and returns an approval request message
  3. Human Review: The approval request includes the tool name, arguments, and context, allowing you to make an informed decision
  4. Approval/Denial: Send an approval response to either execute the tool or provide feedback for the agent to adjust its approach
  5. Continuation: The agent receives the tool result (on approval) or an error message (on denial) and continues processing

Following these best practices will help you implement effective human-in-the-loop workflows while maintaining a good user experience and system performance.

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

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.

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:

Terminal window
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
}'

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:

Terminal window
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
}'

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:

Terminal window
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
}'

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:

Terminal window
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"
}

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.

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:

Terminal window
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"
}

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:

Terminal window
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"
}

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.

Terminal window
# Approve in background after receiving approval_request_message
curl --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
}'

See background mode for resumption patterns.

  • 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_id from the ApprovalRequestMessage.
  • UI trigger: Open the approval UI on approval_request_message only; do not derive UI from stop_reason.