Skip to content

feat: implement SmartChatAgent for real, grounded in the existing ChatManager - #7

Merged
kowshikdev merged 2 commits into
fix/graph-api-and-stabilizefrom
feat/smart-chat-agent
Jul 23, 2026
Merged

feat: implement SmartChatAgent for real, grounded in the existing ChatManager#7
kowshikdev merged 2 commits into
fix/graph-api-and-stabilizefrom
feat/smart-chat-agent

Conversation

@kowshikdev

Copy link
Copy Markdown
Owner

Stacked on #6. Implements the conversational assistant behind /assistant/start, /assistant/chat, /assistant/end — replaces the 501 guard from #6 with the real thing.

Not built from nothing

orchestration/chat_workflow.py's ChatManager already implements the real pipeline: multi-turn history, follow-up detection, intent classification with context, clarification prompts, routing through the super-graph, follow-up suggestions. agents/smart_chat.py is a thin adapter over it, in the exact shape routes_ai.py already calls it in.

Two real gaps found while wiring this up

  • ChatManager.process_message computed confidence and reasoning_trace (both returned by process_user_request) and then discarded them before returning — routes_ai.py's response shape has fields for both. Threaded through.
  • The exception handler in POST /assistant/chat hardcoded confidence: 0.8 on the error path — claiming 80% confidence in a response that is, by definition, a failure. Now None. The handler itself (catch, return "I encountered an issue" as a chat reply) is legitimate — a chat UI showing an inline error is honest degradation, unlike fabricating business data.

Also fixed

SmartChatAgent(repo, use_llm=True) never accepted user_email anywhere in the original (never-ran) code, even though every constructing endpoint has it in the payload. Added it as a real parameter.

use_llm=False is rejected with NotImplementedError rather than silently ignored — no call site passes it, and there's no non-LLM fallback for the underlying pipeline.

Tests

The LLM gateway and the super-graph (which fans out to Redis-backed subgraphs for all six specialized agents) are stubbed at the two points chat_workflow.py itself calls them — EnhancedLiteLLMGateway and process_user_request. That's the real dependency boundary; it lets ChatManager's own logic run for real without needing a live LLM or Redis.

The old TestAssistantEndpointsFailClearly (asserting 501) is gone — replaced with route-registration checks plus real behavioral tests in test_smart_chat.py.

Full suite: 59 pass, 2 skip.

kowshikdev and others added 2 commits July 23, 2026 15:15
…tManager

The conversational assistant behind /assistant/start, /assistant/chat,
/assistant/end. `backend/routes_ai.py` did `from app.smart_chat import
SmartChatAgent` against a module that was never committed anywhere in this
repository -- there is no `app/` package at all. That missing import took the
entire FastAPI app down at boot (fixed with a 501 guard in the previous PR;
this PR replaces the guard with the real thing).

Not built from nothing. `orchestration/chat_workflow.py`'s ChatManager
already implements the real pipeline this needs: multi-turn history,
follow-up detection, intent classification with context, clarification
prompts, routing through the super-graph, follow-up suggestions.
agents/smart_chat.py is a thin adapter over it, in the exact shape
routes_ai.py already calls it in (`agent.context.session_id`,
`agent.chat_sync(message)` -> `{"content", "metadata": {...}}`).

Two real gaps found and fixed while wiring this up:

- ChatManager.process_message computed confidence and reasoning_trace (both
  returned by process_user_request) and then discarded them before
  returning -- routes_ai.py's response shape has fields for both. Threaded
  through rather than left dropped.
- The exception handler in POST /assistant/chat hardcoded confidence: 0.8 on
  the ERROR path -- claiming 80% confidence in a response that is, by
  definition, a failure. Now None. (The handler itself -- catching an
  exception and returning "I encountered an issue" as a chat reply -- is
  legitimate: a chat UI showing an inline error is honest degradation, unlike
  fabricating business data. What was wrong was the specific hardcoded number.)

Also fixed: SmartChatAgent(repo, use_llm=True) never accepted user_email
anywhere in the original (broken, never-ran) code, even though every
constructing endpoint has it in the payload. Added it as a real parameter --
threading it through is what makes the chat actually personalized to who's
asking, and there was no reason to keep discarding it now that this is a real
implementation, not a stub.

use_llm=False is rejected with NotImplementedError rather than silently
ignored: no call site anywhere passes it, and there is no non-LLM mode for
the underlying pipeline to fall back to.

## Tests

The LLM gateway and the super-graph (which itself fans out to Redis-backed
subgraphs for all six specialized agents) are stubbed at the two points
chat_workflow.py itself calls them -- EnhancedLiteLLMGateway and
process_user_request. That's the real dependency boundary of the code under
test; it lets ChatManager's own logic (turn history, follow-up detection,
clarification, response shaping) run for real without needing a live LLM or
live Redis for a full super-graph invocation.

test_app_boots.py's old TestAssistantEndpointsFailClearly (asserting 501) is
gone -- that behavior no longer exists on purpose. Replaced with
TestAssistantEndpointsAreRegistered (routes exist, don't 404) plus the real
behavioral tests in the new test_smart_chat.py.

18 new/changed tests pass. Full suite: 59 pass, 2 skip (Redis-required cases).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kowshikdev
kowshikdev merged commit 2ec61f7 into fix/graph-api-and-stabilize Jul 23, 2026
2 checks passed
kowshikdev added a commit that referenced this pull request Jul 23, 2026
fix: land SmartChatAgent (PR #7 merged into the wrong base)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant