Answers API
Use the Answers API as a Tool
Cookbook: wrap the Answers API as one tool inside your own agent (openai-agents SDK / LangChain).
The Answers API is a closed grounded completion — question in, evidence-backed answer out, no knobs. That shape is exactly what an outer agent wants in a tool: your agent (running on any model, any framework) keeps orchestration and delegates “what do this user’s real health records say?” to Mirobody.
When to prefer this over the Agent API: you already have an agent and need grounded health answers as one capability inside it. When you want Mirobody to be the agent (and call your tools), use the Agent API instead.
openai-agents SDK
Section titled “openai-agents SDK”Your outer agent runs on OpenAI (or any Responses-compatible backend); the tool body calls Mirobody:
from agents import Agent, Runner, function_toolfrom openai import OpenAI
mirobody = OpenAI( api_key="mb_live_...", base_url="https://api.mirobody.ai/v1",)
@function_tooldef health_answers(question: str, user_id: str) -> str: """Answer a question from this end user's REAL health records (labs, vitals, reports). Grounded and citation-backed — use it for anything about the user's own health data.""" resp = mirobody.chat.completions.create( model="mirobody-flash", messages=[{"role": "user", "content": question}], user=user_id, # the end user's stable id (Subject) ) return resp.choices[0].message.content
coach = Agent( name="Wellness coach", model="gpt-4.1", # your model, your orchestration instructions=( "You are a wellness coach. For anything about the user's own labs, " "vitals or reports, call health_answers with their user_id — never guess." ), tools=[health_answers],)
result = Runner.run_sync(coach, "user_id=alice — Should I be worried about my recent glucose?")print(result.final_output)The outer model decides when health data is needed; Mirobody’s agent does the record search, trend math, and evidence citation inside a single tool call.
LangChain
Section titled “LangChain”from langchain_core.tools import toolfrom langchain.agents import create_agent # LangChain v1 agent APIfrom openai import OpenAI
mirobody = OpenAI( api_key="mb_live_...", base_url="https://api.mirobody.ai/v1",)
@tooldef health_answers(question: str, user_id: str) -> str: """Answer a question from this end user's real health records (labs, vitals, reports). Grounded, with traceable evidence.""" resp = mirobody.chat.completions.create( model="mirobody-flash", messages=[{"role": "user", "content": question}], user=user_id, ) return resp.choices[0].message.content
agent = create_agent(model="openai:gpt-4.1", tools=[health_answers])out = agent.invoke({"messages": [ {"role": "user", "content": "user_id=alice — how did my LDL respond to the diet change?"}]})print(out["messages"][-1].content)- Thread the Subject id. The
userparam is the isolation key — if your framework supports per-call context injection, take it from your own auth context rather than letting the model free-type it. - Return evidence too. If your outer agent should show sources, include the response’s
health_records/citationsextensions in the tool’s return value (serialize them alongsidecontent). - Timeouts. A grounded answer runs a real agent turn (seconds, not milliseconds) — give the tool call a generous timeout and stream your outer agent’s narration meanwhile.
- Cost control.
mirobody-flashis the right default inside a tool; reservemirobody-expertfor deep report interpretation. See Models.
See also
Section titled “See also”- Answers API (Chat Completions) — the endpoint being wrapped.
- SDK Examples — the same call in curl, Python and Node.
- Choose Your API — when to reach for the Agent API instead.