feat:修复投顾agent功能
This commit is contained in:
@@ -13,7 +13,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from agent.advisor_agent.auth import ensure_customer_access
|
||||
from agent.advisor_agent.data_query import execute_advisor_data_query
|
||||
from agent.advisor_agent.intent.fund_analysis import build_fund_analysis
|
||||
from agent.advisor_agent.intent.classifier import classify_advisor_intent
|
||||
from agent.advisor_agent.intent.classifier import classify_advisor_intent, resolve_advisor_intent
|
||||
from agent.advisor_agent.intent.talk_script import build_talk_script
|
||||
from agent.advisor_agent.llm import generate_text
|
||||
from agent.advisor_agent.intent.generation_flow import (
|
||||
@@ -69,6 +69,7 @@ from schemas.advisor_agent import (
|
||||
AdvisorDataQueryReq,
|
||||
)
|
||||
from service.nl2sql.query_service import QueryServiceError
|
||||
from nl2sql.query_rewriter import rewrite_query
|
||||
from service.advisor_agent.draft import (
|
||||
detail_draft,
|
||||
discard_draft,
|
||||
@@ -248,10 +249,20 @@ async def chat_stream(
|
||||
)
|
||||
|
||||
runtime = _advisor_runtime(request)
|
||||
classification = await classify_advisor_intent(
|
||||
context_store = SessionContextStore(redis_db.client())
|
||||
conversation_context = build_conversation_context(
|
||||
await context_store.load(user.id, chat_request.session_id)
|
||||
)
|
||||
effective_question = await rewrite_query(
|
||||
chat_request.query,
|
||||
conversation_context,
|
||||
llm_client=getattr(runtime, "llm_client", None),
|
||||
)
|
||||
classification = await classify_advisor_intent(
|
||||
effective_question,
|
||||
getattr(runtime, "llm_client", None),
|
||||
explicit_intent=None,
|
||||
conversation_context=conversation_context,
|
||||
)
|
||||
inferred_intent = classification.intent
|
||||
scope = chat_request.scope
|
||||
@@ -277,11 +288,16 @@ async def chat_stream(
|
||||
await ensure_customer_access(db, advisor_id=user.id, customer_id=int(customer_id))
|
||||
else:
|
||||
resolved_customer_id, _resolve_error = await _resolve_customer_from_query(
|
||||
db, advisor_id=user.id, query=chat_request.query
|
||||
db, advisor_id=user.id, query=effective_question
|
||||
)
|
||||
if resolved_customer_id is not None:
|
||||
customer_id = resolved_customer_id
|
||||
scope = "customer"
|
||||
inferred_intent = resolve_advisor_intent(
|
||||
effective_question,
|
||||
inferred_intent,
|
||||
customer_resolved=customer_id is not None,
|
||||
)
|
||||
|
||||
if customer_id is None:
|
||||
if inferred_intent == AGENT_INTENT_DATA_QUERY:
|
||||
@@ -317,16 +333,12 @@ async def chat_stream(
|
||||
if inferred_intent == AGENT_INTENT_DATA_QUERY:
|
||||
effective_scope = "customer" if customer_id is not None else "advisor"
|
||||
try:
|
||||
context_store = SessionContextStore(redis_db.client())
|
||||
conversation_context = build_conversation_context(
|
||||
await context_store.load(user.id, chat_request.session_id)
|
||||
)
|
||||
result = await execute_advisor_data_query(
|
||||
db,
|
||||
advisor_id=user.id,
|
||||
customer_id=int(customer_id) if customer_id is not None else None,
|
||||
scope=effective_scope,
|
||||
question=chat_request.query,
|
||||
question=effective_question,
|
||||
trace_id=trace_id,
|
||||
session_id=chat_request.session_id,
|
||||
conversation_context=conversation_context,
|
||||
|
||||
Reference in New Issue
Block a user