Skip to main content

Attach to Express

Svantic agents don’t have to live in their own process. When you already have an Express service, you can mount an agent into it with a single call. This guide covers the attach() helper, which wires the A2A endpoints, the Svantic connection, and any declared triggers in one go.

When to use this

  • You have an existing HTTP service and you want it to be callable from Svantic in addition to its normal duties.
  • You want to share middleware, logging, and process lifecycle with that service.
  • You want Svantic traffic to go through your own ingress for auditing.
If you’re starting fresh, new Agent({...}).start() is simpler. Use attach when there’s already an app to embed into.

Minimal example

attach returns an AgentHandle you can use to emit events or detach cleanly:

What attach does

  1. Calls agent.expose(app) — mounts /.well-known/agent-card.json and /send on your Express app.
  2. Mounts each declared trigger (see Triggers).
  3. If mesh is provided, creates a MeshConnector, authenticates, registers the agent, and opens the WebSocket (connected mode) or leaves dispatches to hit public_url/send (hosted mode).
  4. Installs SIGTERM / SIGINT handlers that gracefully deregister.
  5. Returns the handle.

Skipping the mesh

Omit mesh during local development to mount the agent without talking to Svantic at all — useful when running A2A clients directly against your local app:

Adding triggers

Register triggers on the agent with agent.add_triggers() before calling attach(). Hand-written or Forge-generated — each trigger carries a prompt template with {{placeholders}}:
The Triggers guide walks through every kind with worked examples.

Customizing how triggers dispatch

By default, triggers create a Svantic session and send the interpolated prompt to the agent. Override with agent.on_trigger:

Custom endpoint path

agent.expose() defaults to /send. To mount on a different path, use expose() directly instead of attach():

See also