All docs
Examples
Hosted workflow

Revenue definition analytics agent

Answer analytics questions from approved metric definitions instead of prompt guesses.

Problem

Finance agents often invent metric definitions or drift from approved reporting logic.

Why app glue gets messy

Prompt-only guardrails do not guarantee the same definition across users and runs.

How Synapsor helps

Metric definitions live in governed memory and read-only capabilities bind the definition before querying.

Value sources

Example names and seed ids are developer-defined. SESSION values are set by your backend. ARG values come from the SDK/HTTP call. Handles such as wrp://..., evidence://..., and agent-run://... are returned by Synapsor and should be stored for audit/replay.

Read the value-source guide
Expected outcome

The agent returns a number, the SQL it ran, and the definition evidence it used.

Production checks

  • Definition memory is approved before use.
  • Capability is read-only and cannot mutate revenue tables.
  • Evidence bundle points to the metric definition.
  • Unexpected metric names fail instead of inventing definitions.
schema.sql
CREATE TABLE revenue_events (
  id INT PRIMARY KEY,
  tenant_id VARCHAR NOT NULL,
  occurred_on DATE NOT NULL,
  amount_cents INT NOT NULL,
  event_type VARCHAR NOT NULL
);
agent.ddl.sql
CREATE AGENT WORKFLOW finance.metric_answer_flow
SESSION REQUIRE tenant_id, principal
ALLOWED CAPABILITIES (
  finance.answer_metric
)
EVIDENCE REQUIRED
CHECKPOINT EVERY STEP
RETENTION RUNS 365 DAYS, EVIDENCE 365 DAYS;

CREATE AGENT CONTEXT finance.metric_context
ROOT revenue_events AS event
LOOKUP event.tenant_id = SESSION tenant_id
BIND tenant_id FROM SESSION tenant_id
BIND principal FROM SESSION principal
OUTPUT SLOTS
  tenant_id AS event.tenant_id
EVIDENCE ON;

CREATE AGENT CAPABILITY finance.answer_metric
DESCRIPTION 'Answer analytics questions from approved metric definitions'
ARG metric_name VARCHAR REQUIRED
ARG period VARCHAR REQUIRED
HIDDEN tenant_id FROM SESSION tenant_id
HIDDEN principal FROM SESSION principal
USE CONTEXT finance.metric_context
EXECUTION READ ONLY
TOKEN BUDGET MAX OUTPUT TOKENS 1200, MAX INLINE EVIDENCE ITEMS 3,
             MAX REASON COUNT 4, PREFER HANDLES
PLAN
DEFAULT DECISION answer
MEMORY metric_definition
  SCOPE tenant
  SUBJECT metric ARG metric_name
  BUDGET_TOKENS 400
  PROFILE minimal
  INLINE_EVIDENCE handles_only
  PREFER_HANDLES
PAYLOAD definition = STEP_OUTPUT metric_definition
EVIDENCE definition = STEP_OUTPUT metric_definition
END PLAN
RETURNS JSON '{"type":"object","properties":{"answer":{},"definition":{},"evidence_bundle":{}}}'
PROFILE MINIMAL
INLINE EVIDENCE handles_only;
python
db.set_session({"tenant_id": "acme", "principal": "finance_agent"})
run = db.agent_runs.start(
    workflow="finance.metric_answer_flow",
    input={"metric_name": "net_revenue", "period": "2026-05"},
)

result = run.invoke_capability(
    "finance.answer_metric",
    step_key="answer_metric",
    arguments={"metric_name": "net_revenue", "period": "2026-05"},
    response_envelope=True,
)
print(result["result"]["answer"])
print(result["evidence_bundle_id"])