This agent can serve as a customer support, the workflow looks like

First is to set up an SSE server, adding little more basic knowledges about SSE server: SSE is server-sent events, it’s a push technology over a single HTTP connection. the browser listens via EventSource API. for example, def stream(): for i in range(5): yield f”data: Message {i} \n\n” return Response(event_stream(), mimetype=”text/event-stream”). Other types of servers are Websocket, HTTP long polling, gRPC, GraphQL and traditional HTTP server.
Then define a custom MCP service that host the RAG and web search tools using the FastMCP interface. The search_server.py realize these functions:
from agents import set_tracing_export_api_key
from mcp.server.fastmcp import FactMCP
mcp = FactMCP("search Server")
_vector_stored_id = ""
def _run_rag(query: str) -> str: ...
def _summarize_rag_response(rag_output: str) -> str:
@mcp.tool()
def generate_rag_output(query: str) -> str:
def index_document(directory: str):
The above is custom MCP server, it also use external MCP server such as the SQLite server. it’s very easy just add a command line prompt and providing it with a *.db file with the data.
Third, define a planner agent, chooses 4.1-mini model as it achieves a strong balance between reasoning ability and response speed.
from agents import Agent, trace
from agents.mcp import MCPServer, MCPServerSse, MCPServerStdio
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
voice_system_prompt = """[Voice Output Guidelines]
Your responses will be delivered via voice, so please:
1. Use conversational, natural language that sounds good when spoken
2. Keep responses concise - ideally 1-2 sentences per point
3. Avoid technical jargon unless necessary, and explain terms simply
4. Pause naturally between topics using brief sentences
5. Be warm and personable in tone
"""
async def create_insurance_agents(mcp_servers: list[MCPServer]) -> Agent:
"""Create the insurance agent workflow with voice optimization"""
# Main insurance agent with MCP tools
insurance_agent = Agent(
name="InsuranceAssistant",
instructions=voice_system_prompt + prompt_with_handoff_instructions("""
#Identity
You an a helpful chatbot that answers questions about our insurance plans.
#Task
Use the tools provided to answer the questions.
#Instructions
* Information about plans and policies are best answered with sqlite or rag_output tools.
* web_search should be used for answering generic health questions that are not directly related to our insurance plans.
* Evaluate the quality of the answer after the tool call.
* Assess whether you are confident in the answer generated.
* If your confidence is low, try use another tool.
"""),
mcp_servers=mcp_servers,
model="gpt-4.1-mini",
)
return insurance_agent
Then configure Voice, process voice I/O, note the silence_threshold parameter in configuration, this helps decides if the speaker has stopped and the model can answer. Next, we add a simple convenience function for bringing up servers locally. Finally, we can instantiate the custom tool-use server and bring up the service:
import asyncio
try:
asyncio.get_running_loop().create_task(main())
except RuntimeError:
# For Jupyter, use nest_asyncio and run main as a task
import nest_asyncio
nest_asyncio.apply()
task = asyncio.create_task(main())
try:
await task
except KeyboardInterrupt:
print("\nShutting down gracefully...")
except Exception as e:
print(f"\nFatal error: {e}")
raise