Build your first agent
An agent is the top-level unit in Rightbrain. It reasons over an input and calls tools to do real work. This quickstart creates an agent, makes the task you built available to it as a tool, runs it over the API, and streams every step. It reuses the RB_TOKEN, RB_ORG, RB_PROJECT, RB_TASK, and RB_MODEL variables from the previous pages.
Need the task first? Follow Create a task, then come back with its id in RB_TASK.
Create, run and observe
Follow the steps beside the code. Paste each shell file’s commands in order into the same terminal; events.txt shows sample output.
Create the agent
The
instructionis the agent’s standing brief.task_toolsattaches your task as a callable tool. Withrevision_strategy: "follow_active", it uses the task’s active revision.The
201response includes the agent’sid. Save it asRB_AGENTfor the next request. These shell commands requirejqand run in the same terminal.A task tool can also use
is_output_formatterto produce structured final output, oraction_mode: "require_approval"for human sign-off.Run it and stream the events
Send a review in
message. An agent takes turns and calls tools, so the response is Server-Sent Events rather than a single JSON body.-Nmakes cURL show events as they arrive.Run this command once to start work. An HTTP success does not guarantee a successful run: inspect the events for
done,error, orapproval_required.Follow the stream
This is a representative event sequence; tool names and results depend on your task. Each
data:frame contains JSON with anevent_typeand ends with a blank line.Save
metadata.run_idfromdonefor the next step. Savesession_idto continue the conversation by sending it with a subsequent run. Anapproval_requiredevent pauses work; anerrorevent means the run failed.Fetch the run afterward
Replace
{run_id}with the recorded run ID. Fetch the run for its outcome, then fetch its events for the transcript.If the stream disconnects before a terminal event, inspect the run before retrying. When no run ID arrived, use the run history endpoints to find it; starting a new run creates new work.
Python and TypeScript
To create the same agent from an application, use either example below and save the returned ID as RB_AGENT.
Read the event stream in your application
These readers handle completion, approval pauses, failures and interrupted streams. For multi-turn sessions and file inputs, see Run agents via the API.
Set RB_TOKEN, RB_ORG, RB_PROJECT, and RB_AGENT to your credential and resource IDs. These examples send a review-triage message; change it to match your agent. Python requires httpx; TypeScript uses the built-in fetch in Node.js 22+.
HTTP success only means the stream opened. The cURL example prints events; its exit code does not tell you whether the agent completed. The Python and TypeScript readers return completed on done, return waiting_for_human on approval_required, and raise an error on a run failure or unexpected end of stream. formatted_output.content is a string; parse it separately if your formatter produces JSON.
Where to go next
How agents use Tasks, Skills, Connections, Collections, and built-in tools.
Add reusable procedures and selectively loaded reference material.
Give an agent controlled access to Integrations and MCP servers.
Ground an agent through a Collection-backed Task tool.
Pause runs on sensitive tool calls and resume after review.
Multi-turn sessions, file inputs, and the full event reference.
Start agent runs from webhooks, schedules, and inbound email.