Skip to content

Create an AI agent ​

Create a workspace agent with a clear instruction, submit one prompt, and inspect the resulting run. An agent run can use paid AI services, so start with a small, self-contained request.

Prerequisites ​

  • A bearer session token and membership in an existing workspace.
  • Agent access, an active eligible subscription, and sufficient credits for a run.
  • curl, jq, and uuidgen available in your terminal.

Follow Prerequisites to set TOKEN. Set WORKSPACE_ID to your actual workspace identifier. Do not copy an example identifier as a real resource.

Step 1: Create an Agent Definition ​

This workspace operation creates the agent for you. name is required; systemPrompt supplies its instructions.

AGENT_RESPONSE="$(curl --fail-with-body -sS -X POST \
  "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Project update assistant","description":"Summarizes a supplied project update","systemPrompt":"Summarize only the project facts supplied by the user. Keep the answer to two sentences.","memory_mode":"ephemeral"}')"
printf '%s\n' "$AGENT_RESPONSE" | jq .
export AGENT_ID="$(printf '%s\n' "$AGENT_RESPONSE" | jq -er '.data.id')"

The request returns 201 Created, with the agent in data. Retain its returned identifier. This example selects ephemeral memory mode and grants no tools.

Optional fieldMeaning
descriptionA description of the agent's purpose
systemPromptInstructions for the agent
toolIdsActive registered tool keys the agent may call
memory_modetwin_linked or ephemeral
base_modelAn available model key, rather than a model record identifier

The create request does not use the older instructions or modelId fields.

Step 2: Run the Agent ​

Create one idempotency key before sending the request. Keep it unchanged if you need to retry this same run. Generate another key only when you intend to start different work.

bash
export RUN_KEY="$(uuidgen)"

The request body supplies prompt text:

RUN_RESPONSE="$(curl --fail-with-body -sS -X POST \
  "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents/$AGENT_ID/runs" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $RUN_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"The first milestone is complete. The review is scheduled for Friday. Write a short project update."}')"
printf '%s\n' "$RUN_RESPONSE" | jq .
export RUN_ID="$(printf '%s\n' "$RUN_RESPONSE" | jq -er '.data.id')"

A successful request returns 201. Inspect the returned run's status and other available fields; acceptance of the HTTP request is not a promise that every run completes successfully. See Idempotency for retry behavior.

Step 3: Check Run Results ​

Read the agent's run history and find the run using its returned identifier:

curl --fail-with-body -sS \
  "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/agents/$AGENT_ID/runs" \
  -H "Authorization: Bearer $TOKEN" \
  | jq --arg run_id "$RUN_ID" '.data[] | select(.id == $run_id)'

The history request returns 200 with a collection in data and pagination metadata in meta. Check the actual run status and returned result. If the run is still active, wait before reading again; do not submit another run merely to check progress.

Agent Lifecycle ​

Create the agent → submit a prompt → inspect the run. If a request fails, first check its status and error code. A 401 calls for a valid session; a 403 can indicate access, subscription, or policy restrictions; a 429 requires respecting the rate or concurrency limit.

Summary ​

You created an agent, used its actual identifier in a run request, and looked up that run without starting duplicate work.

Next Steps ​

Built with purpose. chainabit.com