AI / Autonomous agents

Autonomous agents

An agent can do more on Stellarium than call APIs. With one set of credentials, it can write and run its own requests, deploy contracts other programs can call, declare events and structs, and react to what happens on the network, all inside a budget you set.

Identity
An API client for one node
Auth
OAuth client credentials
Run
POST /v1/run
Deploy
stellarium deploy

01

Give the agent credentials

An agent acts through an API client. A person does this part once: an organization admin adds funds and creates the client for one node on the Stellarium Platform, setting the most one run may cost and an optional monthly cap. After that, the agent works on its own.

The node you choose decides what the agent can do:

Your organization's nodeAnother organization's listed node
Run requestsyes, no script chargeyes, at the node's price per million script tokens
Deploy contractsyes, freeyes, plus the node's deploy fee, if it has one
Deploy event contractsyes, runs are freeyes, billed per event under a mandate
Declare event types and structsyesno
Emit eventsyes, for event types you ownno

The agent exchanges the client ID and secret for a run token:

Terminal
TOKEN="$(curl -s -X POST https://operator.stellarium.sh/v1/oauth/token \
  -d grant_type=client_credentials \
  -d client_id="$STELLARIUM_CLIENT_ID" \
  -d client_secret="$STELLARIUM_CLIENT_SECRET" \
  | jq -r .access_token)"

A run token lasts 15 minutes and works on any number of runs, but only on the node its client was created for. When it expires, the agent asks for a new one. To use several nodes, give the agent one client for each.

02

Find what's on the network

Before writing any code, an agent can read what the network offers. These routes need no authorization, and return one page at a time with a nextOffset:

Terminal
curl "$STELLARIUM_NODE_URL/v1/resources?limit=500"
curl "$STELLARIUM_NODE_URL/v1/contracts?limit=500"
curl "$STELLARIUM_NODE_URL/v1/events?limit=500"
curl "$STELLARIUM_NODE_URL/v1/structs?limit=500"

Resources come with descriptions, parameter types, return types and prices, so a model can choose a function and call it correctly from the listing alone. Contracts also include their full source, so the agent can read exactly what one does before paying for it.

03

Run its own requests

A request is a one-off RequestScript program, and the quickest way for an agent to act. The agent writes the script, sends it, and reads the result. Nothing is deployed. One request can call any number of resources, including AI models.

AskSonnet.req
request AskSonnet {
  const sonnet: sh.stellarium.inference.claude.Sonnet

  const reply = sonnet.message(prompt: "Name one use for a weather API", maxTokens: 200)
  if (reply.error != null) {
    return reply.error.message
  }

  return reply.value
}
Terminal
curl -X POST "$STELLARIUM_NODE_URL/v1/run" \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d "$(jq -n --rawfile source AskSonnet.req '{source: $source}')"
Response
{ "returnValue": "Plan a delivery route around storms", "usage": { "tokens": 31 } }

RequestScript has no loops, so the most tokens a script can execute is known before it runs. A generated script can't spin forever, and one that would cost more than the client allows is refused before it starts.

04

Deploy contracts, events and structs

When a request is worth keeping, the agent can deploy it. Deployed code stays on the network, where other programs can use it after the agent's session ends.

Deploy aWhen the agent wants toRoute
Structname a data shape every node can checkPOST /v1/structs
Event typeannounce that something happenedPOST /v1/events
Contractpublish a function anyone can callPOST /v1/contracts
Event contractrun code whenever an event arrivesPOST /v1/contracts

Here, an agent publishes a summarizer. It writes one declaration per file in a directory:

stellarium/Digest.req
struct com.example.Digest@1(topic: string, summary: string)
stellarium/DigestReady.req
event com.example.DigestReady@1(digest: com.example.Digest@1)
stellarium/Summarize.req
contract com.example.Summarize@1 {
  const sonnet: sh.stellarium.inference.claude.Sonnet

  pub fn summarize(topic: string, text: string): com.example.Digest@1 {
    const reply = sonnet.message(prompt: "Summarize in one line: ${text}", maxTokens: 400)
    if (reply.error != null) {
      var failed: com.example.Digest@1 = { topic: topic, summary: "unavailable" }
      return failed
    }

    var digest: com.example.Digest@1 = { topic: topic, summary: reply.value }
    emit com.example.DigestReady(digest: digest)
    return digest
  }
}
stellarium/OnDigestReady.req
contract com.example.OnDigestReady@1 consumes com.example.DigestReady@1 {
  fn on(digest: com.example.Digest@1) {
    var state(digest.topic) latest: string = ""
    latest = digest.summary
  }
}

The Stellarium CLI is the simplest way to deploy them. It gets its own run token, and deploys structs first, then event types, then contracts, so each declaration can name the ones before it. --dry-run compares each file's declaration with the node without changing anything. --output agent prints plain text, and piped output is JSON by default.

Terminal
npm install -g stellarium-cli

export STELLARIUM_NODE_URL=https://node.example.com    # no /v1
export STELLARIUM_OPERATOR_URL=https://operator.stellarium.sh/v1
export STELLARIUM_CLIENT_ID=cli_...
export STELLARIUM_CLIENT_SECRET=cs_...

stellarium --output agent deploy --dry-run stellarium/
stellarium --output agent deploy stellarium/
Output
deployed struct com.example.Digest@1 stellarium/Digest.req
deployed event com.example.DigestReady@1 stellarium/DigestReady.req
deployed contract com.example.Summarize@1 stellarium/Summarize.req
deployed contract com.example.OnDigestReady@1 stellarium/OnDigestReady.req
summary: 4 deployed, 0 unchanged
  • Deploying again is safe. Versions the node already has with the same content are left alone and cost nothing, so the agent can retry a deploy freely.
  • Changes need a new version. Versions are immutable. To change a contract, the agent deploys it as @2. Calls always run the latest version.
  • Dry runs don't check contract bodies. A syntax error in a body only shows up on the real deploy.
  • Other nodes learn right away. A node announces new contracts to its peers after each deploy.
  • Names are taken once. The first organization to deploy a contract owns every version of it, so use a path your organization controls.

05

Call and react

A contract is a resource like any other. Once it's deployed, the agent, or any other program on the network, binds it by name and calls one of its functions, here summarize:

SummarizeStandup.req
request SummarizeStandup {
  const summarize: com.example.Summarize

  return summarize.summarize(topic: "standup", text: "Shipped the fix. Docs are next.")
}

When Summarize succeeds, it emits DigestReady. The event contract runs on its own, with no request from the agent, and stores the summary in contract state. State is private, so the agent reads it with its client:

Terminal
curl "$STELLARIUM_NODE_URL/v1/contracts/com.example.OnDigestReady/state" \
  -H "Authorization: Bearer $TOKEN"

That gives the agent memory between sessions: state survives restarts, and it's saved only when a run succeeds. Events can also connect agents that know nothing about each other. Any organization can deploy an event contract for an event type that isn't restricted, on any node that knows the type.

06

Who pays

Everything an agent spends comes from its organization's prepaid balance, in USD. Each run is held first, and only what it used is charged.

ActionWhat the agent's organization pays
Run a requestthe node's price for script tokens executed, free on its own nodes, plus any paid functions the script calls
Call an AI modelthe tokens used, never more than the signed ceiling
Deploy a contractthe node's deploy fee, free on its own nodes
Call a contractthe tokens it executes and every paid call it makes, free in its own organization
Have its contract callednothing: the caller pays
Emit an eventonly the publishing run's tokens
Run an event contracteach run, under a mandate on other organizations' nodes, free on its own

A contract is billed at its hosting node's listed price, and that node's organization earns it, so an agent's contract on your own listed node can earn when others call it.

07

Keep it within limits

An agent makes its own decisions, so set its limits before it starts. The network enforces these, whatever code the agent writes:

  • Max per run. The most one run can cost, including its paid calls. It defaults to $1.
  • Monthly cap. Set one on any client an agent uses unattended.
  • One node per client. A leaked run token works on one node, for at most 15 minutes.
  • Revocation. Revoking a client on the Platform refuses its billed runs at once and stops new tokens. Unbilled runs on your own nodes can continue until its current token expires.
  • Bounded chains. Contracts call each other at most 8 deep, event chains stop at 4, and a run emits at most 16 events.

A few things need care from you, because the network won't catch them:

  • Contract source is public. GET /v1/contracts returns every version, so an agent must never put a secret in a contract.
  • Event contracts outlive their token. On another organization's node, one keeps running and billing under its mandate. To stop it, revoke the mandate or the client under API clients on the Platform.
  • Anyone can call a contract. Callers pay for it, but if it emits your events, they trigger those events as you. Have a person review what an agent deploys under a path you care about.
  • Keep the secret away from the model. Give the client secret to the tool that fetches tokens, not to the prompt, where text the agent reads from the network could try to extract it.

08

Recover from errors

Most failures tell the agent what to do next. A resource call that fails doesn't fail the run: it comes back as an error value the script can handle. These statuses come from the node itself:

StatusMeaningWhat the agent should do
400The source is invalid or names an unknown struct or event typeFix the source, using the error message
401The token is invalid or expiredGet a new run token and retry
402Over the max per run, the balance or the monthly capDon't retry as is: make the script cheaper, or ask a person
403Not allowed for this organization, or the node was unlistedUse a client of the node's organization, or another node
409The version exists or the name is takenDeploy a new version, or choose another path
413The source is too largeSplit the contract
422The script failed while running, and is charged for what it executedRead details and fix the script
503The operator is unreachable, or the node isn't enrolledRetry later

The CLI reports the same kinds of failure as exit codes: 2 for configuration, 3 for authentication or a refused deploy, 4 for an invalid script or version conflict, 5 for a network error worth retrying, and 6 when the operator refuses the deploy fee.

09

Further reading

Docs

API clients

Run tokens, script tokens and how a billed run is held and captured.

Docs

Deploy from CI

Check agent-written .req files on pull requests and deploy them on merge.

Claude

Claude Skill

Add the Stellarium skill to Claude, so it can work with the network.

Building an agent on Stellarium? Tell us about it on Discord.