Skip to main content
This agent answers questions about orders. It reads order data through a function tool that runs in your code, so the agent never touches your database. It can ask for a refund, but your code decides; here it only opens a ticket for a person to review. You will use: function tools and streaming. No sandbox.

How it works

Two tools, each with one narrow job. lookup_order reads. request_refund does not move money; it records a request for a person. Your program must answer the function calls, or the turn waits. The program below answers them while the stream is open.

The program

Examples on this page assume the settings from the shared setup. ORDERS stands in for your database.
The first message has no order ID, so the agent asks for one. The second one calls lookup_order. The third one calls request_refund, and your code opens a ticket instead of refunding.

Make it yours

  • Check who is asking. In production, look up the order only if it belongs to the signed-in customer. The model does not know your permissions; your handler does.
  • One session per conversation. Store the session ID with the chat thread or ticket, and send each new message to it.
  • Answer from a worker. If tool calls should run somewhere other than the code that sends messages, answer them from any process instead. See answer from any process.
  • Report tool failures honestly. Returning {"error": ...} lets the model tell the customer what went wrong, instead of inventing an answer.