Agent Not Completing Tasks
Problem: Agent status stuck at “running” indefinitely Quick Diagnostic: Check if agent needs input, task is too complex, or website is down.Diagnose the Issue
- JavaScript
- Python
- HTTPie
Copy
async function diagnoseStuckAgent(sessionId) {
const status = await client.getSessionStatus(sessionId);
console.log(`Status: ${status.status}`);
const messages = await client.getMessages(sessionId);
const questions = messages.messages.filter(m => m.type === 'QUESTION');
if (questions.length > 0) {
console.log(`Agent waiting for answer to: ${questions[questions.length - 1].content}`);
return 'needs_input';
}
if (messages.messages.length > 0) {
const lastMsg = messages.messages[messages.messages.length - 1];
console.log(`Last message: [${lastMsg.type}] ${lastMsg.content}`);
}
if (!messages.has_agent) {
console.log('Agent disconnected!');
return 'disconnected';
}
return 'unknown';
}
Copy
def diagnose_stuck_agent(session_id):
status = get_status(session_id)
print(f"Status: {status}")
messages = get_messages(session_id)
questions = [m for m in messages["messages"] if m["type"] == "QUESTION"]
if questions:
print(f"Agent waiting for answer to: {questions[-1]['content']}")
return "needs_input"
if messages["messages"]:
last_msg = messages["messages"][-1]
print(f"Last message: [{last_msg['type']}] {last_msg['content']}")
if not messages.get("has_agent"):
print("Agent disconnected!")
return "disconnected"
return "unknown"
Copy
# Check status
http GET https://api.agi.tech/v1/sessions/$SESSION_ID/status \
Authorization:"Bearer $AGI_API_KEY"
# Get messages and check for questions
http GET https://api.agi.tech/v1/sessions/$SESSION_ID/messages \
Authorization:"Bearer $AGI_API_KEY" | jq '.messages[] | select(.type=="QUESTION")'
Solutions
Agent Needs Input
Agent Needs Input
The agent is waiting for your response to a question:
- JavaScript
- Python
- HTTPie
Copy
const messages = await client.getMessages(sessionId);
for (const msg of messages.messages) {
if (msg.type === 'QUESTION') {
console.log(`Q: ${msg.content}`);
const answer = await getUserInput('A: ');
await client.sendMessage(sessionId, answer);
}
}
Copy
messages = get_messages(session_id)
for msg in messages["messages"]:
if msg["type"] == "QUESTION":
print(f"Q: {msg['content']}")
answer = input("A: ")
send_message(session_id, answer)
Copy
# Get questions
QUESTIONS=$(http GET https://api.agi.tech/v1/sessions/$SESSION_ID/messages \
Authorization:"Bearer $AGI_API_KEY" | jq '.messages[] | select(.type=="QUESTION")')
# Respond to question
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Your answer here"
Task Too Complex
Task Too Complex
Break down complex tasks into smaller steps:
- JavaScript
- Python
- HTTPie
Copy
// ❌ Don't do this:
// await client.sendMessage(sessionId, "Research 10 companies, compare prices, analyze reviews...");
// ✅ Do this instead:
await client.sendMessage(sessionId, "Research Company A");
await client.waitForCompletion(sessionId);
await client.sendMessage(sessionId, "Research Company B");
await client.waitForCompletion(sessionId);
// ... continue with remaining companies
Copy
# ❌ Don't do this:
# send_message(session_id, "Research 10 companies, compare prices, analyze reviews...")
# ✅ Do this instead:
send_message(session_id, "Research Company A")
wait_for_completion(session_id)
send_message(session_id, "Research Company B")
wait_for_completion(session_id)
# ... continue with remaining companies
Copy
# Send first task
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Research Company A"
# Wait for completion, then send next task
# (Poll status until finished)
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Research Company B"
Website Issues
Website Issues
The target website may be down or blocking requests:
- JavaScript
- Python
- HTTPie
Copy
await client.sendMessage(sessionId, `
Check if example.com is accessible.
If not, try alternative: backup-site.com
`);
Copy
send_message(session_id, """
Check if example.com is accessible.
If not, try alternative: backup-site.com
""")
Copy
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Check if example.com is accessible. If not, try alternative: backup-site.com"
Timeout & Restart
Timeout & Restart
Set a timeout and restart with a simpler task if needed:
- JavaScript
- Python
- HTTPie
Copy
try {
const result = await client.waitForCompletion(sessionId, { timeout: 300000 }); // 5 minutes
} catch (e) {
if (e.name === 'TimeoutError') {
await client.cancelSession(sessionId);
// Restart with simpler task
await client.sendMessage(sessionId, "Simpler version of the task");
}
}
Copy
try:
result = wait_for_completion(session_id, timeout=300) # 5 minutes
except TimeoutError:
cancel_session(session_id)
# Restart with simpler task
send_message(session_id, "Simpler version of the task")
Copy
# Set timeout in polling loop
TIMEOUT=300
START=$(date +%s)
while [ $(($(date +%s) - START)) -lt $TIMEOUT ]; do
STATUS=$(http GET https://api.agi.tech/v1/sessions/$SESSION_ID/status \
Authorization:"Bearer $AGI_API_KEY" | jq -r '.status')
if [ "$STATUS" = "finished" ]; then
break
fi
sleep 2
done
Agent Returns Incomplete Results
Problem: Agent finishes but doesn’t provide all requested data Solution: Be explicit about completeness requirements- JavaScript
- Python
- HTTPie
Copy
await client.sendMessage(sessionId, `
Find prices for Product X on these sites:
- site1.com
- site2.com
- site3.com
IMPORTANT:
- You must check ALL three sites
- If a site is inaccessible, note it clearly
- Return "NOT_FOUND" for unavailable data
- Do not skip any sites
Return as JSON:
{
"site1.com": {"price": 99.99, "available": true},
"site2.com": {"price": null, "available": false, "reason": "Out of stock"},
"site3.com": {"error": "Site inaccessible"}
}
`);
Copy
send_message(session_id, """
Find prices for Product X on these sites:
- site1.com
- site2.com
- site3.com
IMPORTANT:
- You must check ALL three sites
- If a site is inaccessible, note it clearly
- Return "NOT_FOUND" for unavailable data
- Do not skip any sites
Return as JSON:
{
"site1.com": {"price": 99.99, "available": true},
"site2.com": {"price": null, "available": false, "reason": "Out of stock"},
"site3.com": {"error": "Site inaccessible"}
}
""")
Copy
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Find prices for Product X on site1.com, site2.com, site3.com. IMPORTANT: Check ALL three sites. If inaccessible, note clearly. Return NOT_FOUND for unavailable data. Return as JSON with site, price, available, reason/error."
Always specify what to do with missing or unavailable data in your instructions. Use explicit lists and require confirmation of completeness.
Agent Makes Errors
Problem: Agent provides incorrect information Best Practices:1
1. Add Verification Steps
Request the agent to verify its findings:
- JavaScript
- Python
- HTTPie
Copy
await client.sendMessage(sessionId, `
Find the price of Product X on amazon.com
Steps:
1. Search for "Product X exact name"
2. Verify it's the correct product (check SKU if available)
3. Get the price from the main product page
4. Double-check the price in the cart
Return the verified price.
`);
Copy
send_message(session_id, """
Find the price of Product X on amazon.com
Steps:
1. Search for "Product X exact name"
2. Verify it's the correct product (check SKU if available)
3. Get the price from the main product page
4. Double-check the price in the cart
Return the verified price.
""")
Copy
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Find the price of Product X on amazon.com. Steps: 1. Search for exact name 2. Verify correct product (check SKU) 3. Get price from product page 4. Double-check in cart. Return verified price."
2
2. Request Sources
Always ask for source URLs and dates:
- JavaScript
- Python
- HTTPie
Copy
await client.sendMessage(sessionId, `
Research Company A's revenue.
Include:
- The revenue figure
- The source URL
- The date of the information
- Whether it's confirmed or estimated
I will verify the sources.
`);
Copy
send_message(session_id, """
Research Company A's revenue.
Include:
- The revenue figure
- The source URL
- The date of the information
- Whether it's confirmed or estimated
I will verify the sources.
""")
Copy
http POST https://api.agi.tech/v1/sessions/$SESSION_ID/message \
Authorization:"Bearer $AGI_API_KEY" \
message="Research Company A's revenue. Include: revenue figure, source URL, date of information, confirmed or estimated. I will verify the sources."
3
3. Validate Results
Add validation logic in your code:
- JavaScript
- Python
- HTTPie
Copy
function validateAgentResult(result) {
// Check for obvious errors
if (result.price < 0) {
throw new Error('Invalid negative price');
}
if (result.price > 100000) {
console.warn(`Warning: High price detected: ${result.price}`);
}
// Verify sources exist
if (result.source_url && !result.source_url.startsWith('http')) {
throw new Error('Invalid source URL');
}
return true;
}
Copy
def validate_agent_result(result):
# Check for obvious errors
if result.get("price", 0) < 0:
raise ValueError("Invalid negative price")
if result.get("price", 0) > 100000:
print(f"Warning: High price detected: {result['price']}")
# Verify sources exist
if "source_url" in result:
if not result["source_url"].startswith("http"):
raise ValueError("Invalid source URL")
return True
Copy
# Validate in your processing script
PRICE=$(echo "$RESULT" | jq -r '.price')
if (( $(echo "$PRICE < 0" | bc -l) )); then
echo "Error: Invalid negative price"
exit 1
fi