The ConversationBrain is Agentic AI’s intelligence layer that bridges natural conversation with executable actions. It analyzes user speech in real-time to determine intent, distinguish commands from casual chat, and route actionable requests to ClawdBot for execution.
For ambiguous cases, uses Gemini Flash for fast classification (conversation_brain.py:352):
prompt = f"""You are a simple intent classifier. Determine if the user wants you to DO something or just chatting.Recent conversation:{context}User said: "{user_text}"Is this a request to DO something?Answer with just ONE word: YES or NO"""
The prompt is intentionally liberal - defaults to “actionable” when uncertain. ClawdBot’s LLM handles ambiguity on the execution side.
ClawdBot’s response is spoken back to the user (conversation_brain.py:276):
if response and self._on_clawdbot_response: # Feed response back to AI to speak it await self._on_clawdbot_response(response)
The on_clawdbot_response callback sends the result to the Realtime API with a relay prompt:
# From audio_bridge.py:314prompt = f"""The system has retrieved the following information.Please relay this information naturally and concisely.Information to relay:{response}"""
Assistant turns are simpler - just buffered and flushed:
# Buffer AI's speech fragmentsadd_assistant_transcript("I'll")add_assistant_transcript(" check")add_assistant_transcript(" your emails now.")# Flush when AI finishes speakingawait flush_assistant_turn()
Assistant transcripts are not sent to Telegram. Only executable commands go to the ClawdBot agent.
# Instant classification (no LLM call)if text_lower in non_actionable_phrases: return "conversation", None, Falseif any(kw in text_lower for kw in action_keywords): return "action", {...}, True
# conversation_brain.py:385except Exception as e: logger.error("Error analyzing intent", error=str(e)) # Default to actionable to avoid missing commands return "action", {"original_request": user_text}, True
Fail-safe behavior: On error, defaults to treating requests as actionable. This ensures important commands aren’t ignored, at the cost of potentially over-routing casual conversation.
except asyncio.TimeoutError: return "I'm still working on that. It's taking longer than expected."except Exception as e: return f"Sorry, I encountered an error: {str(e)}"
Errors are spoken to the user naturally, keeping the conversation flowing.
Craft system instructions that emphasize the agent’s capabilities:
agent_system_instruction = """You are Alchemy, an AI agent with REAL capabilities:- You CAN check and send emails- You CAN send messages to Telegram, WhatsApp, Discord- You CAN search the webWhen asked to do something, SAY "I'll do that now" and describe what you're doing."""
This primes the LLM to acknowledge commands confidently.
# ✅ Good - clear binary choice"Is this a request to DO something? Answer YES or NO"# ❌ Bad - allows uncertainty"What is the user's intent? Explain your reasoning."
User: "How are you?" ↓Brain: Quick match on common phrase ↓Classification: conversation (heuristic) ↓No ClawdBot call ↓AI responds naturally from conversation