Repository navigation
[Deep Agent 15/15] Serve the deep agent behind chat_with_agent: engine switch, durable threads, streaming, HITL (#43) - #64
Open
stavp-star wants to merge 1 commit into
Open
stavp-star wants to merge 1 commit into
stavp-star wants to merge 1 commit into
Conversation
…rable threads - deep_agent/service.py: process-wide agent, AsyncPostgresSaver when DEEP_AGENT_CHECKPOINT_DB_URL is set (else in-memory), legacy Redis stream events (deep:<tool>, deep:answer), legacy JSON response contract + engine/verification/confidence, clarification as free-text HITL interrupt resumed with the user's answer on the same thread - chat_with_agent: engine argument / AGENT_ENGINE default; deep-* thread ids are routed back to the deep agent on resume; non-interactive calls get the clarifying question as the answer - answer middleware resets the structured answer each turn (a turn without a new answer no longer re-reports the previous one) - backend: optional engine passthrough and engine/verification/confidence response fields - create_deep_agent(checkpointer=...) Closes #43 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
15 tasks
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43 · Part of epic #49 · Stack position 15/15. Base:
deep-agent/44-evals(#63), auto-retargets on merge.Where the integration lives
The issue said "route
/chat", butagent/main.pydoesn't mountrouters/chat.py: the agent service app is the MCP server. The real path is UI → backendPOST /api/agent/chat→ MCP toolchat_with_agent, and that's where the engine switch is.What
Engine selection (
agent/mcp_server.py)engineargument (legacy|deep), defaulting toAGENT_ENGINE(defaultlegacy, so nothing changes until it's chosen).deep-IDs, and resumes are routed by thread ID: a deep thread always returns to the deep agent and a legacy thread to the legacy graph, even if the caller doesn't resendengine.backend/app/routers/agent.py): optionalenginein the request, forwarded only when set (older agent deployments keep working). Responses gain optionalengine,verification, andconfidence.deep_agent/service.pyDeepAgentContext(connection, user) plus the thread ID.AsyncPostgresSaverover a pooled connection whenDEEP_AGENT_CHECKPOINT_DB_URLis set (setup()is idempotent); otherwise an in-memory saver, with a warning.agent_stream:{thread_id},{"thread_id", "node", "status"}), fordeep:<tool>active/completed/error and a finaldeep:answer. The backend SSE relay works unchanged. The response'sexecution_pathlists the tool steps.status,summary,sql_query,sql_explanation,trace_id,execution_path,is_unanswerable,raw_data_ref).summaryis rendered from the verified Trino rows ([Deep Agent 9/15] Structured final answer bound to the actually-executed SQL (#41) #58).needs_clarification→status: "interrupted",interrupt_details: {"type": "hitl_escalation", "subtype": "clarification", "reason": <question>}. That's the free-text prompt the UI already renders. The reply (resume_valuestring or{"feedback": ...}) becomes the next user message on the same thread. Withhitl_enabled=false, the question is returned as a completed answer instead.Bugs found and fixed while building this
structured_responsepersisted in thread state, so a turn ending without a new answer re-reported the previous turn's answer. Reproduced ("turn2: matched turn1").AnswerVerificationMiddleware.before_agentnow clears it every turn, and best-effort answers use only the current turn's executions. Regression test added. This also affected the CLI's--session-memory.adcdce9) and merged forward through [Deep Agent 13/15] Curated Utils-Server tools via the Jarvis Registry MCP gateway (#47) #62 and [Deep Agent 14/15] Execution-accuracy eval harness (deep vs legacy) + CI (#44) #63.Acceptance criteria
DEEP_AGENT_TEST_PG_URL.run_deep_agent.pyhas nosys.pathhacks and runs viauv run([Deep Agent 1/15] Hygiene: CLI entry point, remove committed logs & scratch files (#46) #50)Known gaps / follow-ups
deep:*). If the execution-graph visualisation only knows legacy node names, it may need a small mapping. Not verified without the UI running.allowed_tables,allowed_statuses,extractors,active_skills, andexecution_modefor now. Mappingallowed_tablesonto the catalog / tools is the natural next step.query_approval) has no deep-agent equivalent, because the deep agent executes exploratory SQL itself. If approval-before-final-execution is required, add aninterrupt_ongate on the final answer.Rollout
AGENT_ENGINE=legacywith per-requestengine: "deep"for internal users →deep-agent-eval --gatepasses on the expert gold set (#63) →AGENT_ENGINE=deep→ remove the legacy graph.Testing
agent/tests/deep_agent/test_service.py: 16 tests (contract mapping, clarify→resume, stream events, stale-answer regression, engine routing incl. resume affinity, hitl off, Postgres durability)backend/tests/test_agent_engine.py: 3 tests (engine forwarding, omission, validation). Note: the backend suite creates/drops atext2sql_testdatabase on the configured Postgres, by design.ENABLE_KEYCLOAK=false)🤖 Generated with Claude Code