Agent that takes action
Example OrchaJS agent that calls APIs, databases, or any Node.js code as a local action.
01const orders = {02 ord_1001: {03 orderId: "ord_1001",04 status: "in_transit",05 expectedDelivery: "2026-10-02",06 },07};08 09export default async function lookupOrder({ orderId }) {10 const order = orders[orderId];11 12 if (!order) {13 throw new Error(`Order ${orderId} was not found.`);14 }15 16 return order;17}Let the agent do real work
This example is a complete order agent with one action: lookup_order. The
model receives a typed tool definition, chooses when to call it, and supplies
arguments that match the configured JSON Schema.
The action's index.js is ordinary application code. It can contain any
trusted Node.js logic: query your database, call an internal API, use an npm
package, invoke a third-party SDK, read from a service, or perform a
calculation. The in-memory order lookup here keeps the example runnable.
Orcha validates the model arguments, runs index.js, validates its return
value, gives that result back to the model, and continues until the agent
produces its final answer. Your application does not need to manage that tool
loop.
Select any file in the editor to inspect the complete standalone project.
Understand each file
orcha/orderAgent/actions/lookupOrder/index.json
Defines the model-facing tool and validates its arguments and returned value.
- parameters is the JSON Schema for model-generated input.
- outputSchema validates what index.js returns.
- Orcha executes index.js by default, so execution does not need to be specified.
orcha/orderAgent/actions/lookupOrder/index.js
Contains ordinary executable application code.
- It can query a database, call an API, use an SDK, invoke a third-party service, or run any trusted Node.js logic.
- Its default export receives the validated parameters and returns the action result.
orcha/orderAgent/index.json
Configures the order agent and its model.
orcha/orderAgent/instructions.md
Tells the agent when to use the action and how to treat its result.
orcha/index.ts
Registers orderAgent. Direct action folders are discovered automatically.
app.ts
Runs the agent. Orcha executes the action and returns its result to the model automatically.
Next: put a human in the loop.