Skip to main content
Run a Veryfront agent in your own process, in any language, while Veryfront records the run, its events, and its result. Your process acts as an agent worker: it registers once, claims runs that Veryfront admits for it, appends events with a run-scoped token, and finishes the run.

Before you start

You need curl, jq, uuidgen, and an API credential with permission to manage agents, conversations, and runs, plus project.runtime.manage to register the worker. Set PROJECT to your project reference and PROJECT_ID to the project’s UUID. Create the agent definition in the project first. Set AGENT_ID to its ID. The definition names the agent; your worker executes it.

1. Register the worker

Call POST /agent-workers/projects/{project_reference}/workers. Choose an implementation_kind that names your runtime and a stable worker_key for this process:
register-worker.sh
The response contains the worker and its token. Store the token: Veryfront returns it only once.

2. Store the user message

A worker run starts from a persisted user message. Create a conversation with one. Omit type: the API creates a chat conversation, which is the type for top-level runs.
create-conversation.sh
For a later turn, append the user message with POST /conversations/{conversation_id}/messages before you start the run.

3. Start the run on your worker

Call POST /runs with conversation_id and config.agent_admission. Set mode to worker and implementation_kind to the value your worker registered with:
start-run.sh
Veryfront accepts the run with 202 and holds it for a matching worker. Add worker_key to agent_admission to pin the run to one worker. execution.runtime overrides don’t apply to agents. Use agent_admission instead.

4. Claim the run

Poll POST /agent-workers/workers/{worker_id}/claim with the worker token:
claim.sh
run is null when nothing is waiting, so the loop polls until a run arrives. An HTTP error stops the loop and prints the response body. The claimed run includes the conversation and message IDs, so your code can read the user message. Renew the lease with POST /agent-workers/workers/{worker_id}/runs/{run_id}/lease while the run takes longer than the lease. That path takes the worker run ID (WORKER_RUN_ID), not canonical_run_id; the Runs endpoints below use RUN_ID. A renewal that returns run: null means the lease is gone.

5. Append events

Append events with POST /runs/{run_id}/events and the run_event_token. API keys can’t append events.
append-events.sh
Events follow the run event format. Veryfront writes RUN_STARTED and RUN_FINISHED itself.

6. Finish the run

Call POST /runs/{run_id}/succeed with the run credentials:
succeed.sh
Both terminal calls require an Idempotency-Key header; reuse the same key when you retry. Call POST /runs/{run_id}/fail instead when your code fails.

7. Verify the result

Read the run with GET /runs/{run_id} and its events with GET /runs/{run_id}/events:
verify.sh
status is completed and output holds the result you sent. Studio shows the run and its events like any hosted run.

Python example

The same loop with the OpenAI SDK, calling the AI gateway: Install the dependencies and export the worker credentials from step 1 and a model ID:
setup.sh
Then run python worker.py:
worker.py
The example renews the lease once before the model call and assumes that call finishes within LEASE_SECONDS. For longer work, renew the lease on a timer until the run ends. If the lease expires, another worker can claim the run and your succeed call fails. The AI gateway doesn’t accept the run’s auth_token, so the example calls it with VERYFRONT_API_KEY. Gateway usage is billed to the API key’s account and isn’t attributed to the run. Read the user message from the conversation in the claimed run instead of PROMPT in production code.

API references

Next steps