from moxn import MoxnClient
from moxn.types.content import Provider
from anthropic import Anthropic
import asyncio
async def handle_customer_query(query: str, customer_id: str):
async with MoxnClient() as client:
session = await client.create_prompt_session(
prompt_id="product-help-prompt",
branch_name="main",
session_data=ProductHelpInput(query=query)
)
async with client.span(
session,
name="customer_support_request",
metadata={
"customer_id": customer_id,
"query_length": len(query)
}
) as root_span:
# Step 1: Classify the query
classification = await classify_query(query)
# Step 2: Search for relevant docs
docs = await search_knowledge_base(query)
# Step 3: Generate response with all context in metadata
async with client.span(
session,
name="generate",
metadata={
"classification": classification,
"doc_count": len(docs)
}
) as span:
anthropic = Anthropic()
response = anthropic.messages.create(
**session.to_anthropic_invocation()
)
await client.log_telemetry_event_from_response(
session, response, Provider.ANTHROPIC
)
return response.content[0].text
asyncio.run(handle_customer_query("How do I reset my password?", "cust_123"))