Harmonyalpha
DocsSkillsAboutSource ↗Sign in
Harmony

Open source platform for agents. Bring your own agent. Harmony provides the substrate.

Project

  • Source
  • Docs
  • Architecture

Status

  • alpha · skeleton
  • No public API yet
© 2026 Groupanyplatform.groupany.ai

Get started

  • Get started

API reference

  • API overview
  • Authentication
  • Workspaces
  • Sessions, events, traces
  • Skills
  • Agents
  • Tools
  • Teams
  • Projects
  • A2A protocol
  • Evaluation
  • Deployments

Webhooks

  • Webhook Triggers

MCP

  • MCPdraft

CLI

  • CLIdraft

Database model

  • Database model

Research

  • LangChain — what we learn from them

Status

  • Status

Roadmap

  • Roadmap

Sessions, events, traces

This is the heart of Harmony: how a run is started, what it emits, and how you read it back. A run (a "session") is an append-only stream of typed events. Run.projection is derived state — never written directly (Decision 0008).

Endpoints

POST  /api/v1/workspaces/{slug}/sessions   → 201, start a run (cookie auth)
GET   /api/v1/sessions/{id}                → run metadata + inline events[]
GET   /api/v1/sessions/{id}/stream         → live Server-Sent Events

All three are authenticated with the browser session cookie (next-auth.session-token), and the caller must be a member of the run's workspace. There is no bearer-token path on these routes and no short-lived session token — a run is identified by its id, not by a credential.

Start a run

POST /api/v1/workspaces/{slug}/sessions. The body names an agent in the workspace and the input that kicks off the turn. Pass thread_id to continue an existing conversation; omit it (or send null) to open a new one (Decision 0016).

curl -X POST https://platform.groupany.ai/api/v1/workspaces/acme-research/sessions \
  -b "next-auth.session-token=$COOKIE" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "research-agent",
    "input": "What changed in the EU AI Act last quarter?"
  }'

Response 201:

{
  "run": {
    "id": "run_…",
    "status": "active",
    "started_at": "2026-05-28T19:02:11.000Z"
  },
  "thread": { "id": "thr_…" },
  "uri": "harmony://ws/acme-research/runs/run_…"
}

Continue an existing conversation by passing its thread id:

curl -X POST https://platform.groupany.ai/api/v1/workspaces/acme-research/sessions \
  -b "next-auth.session-token=$COOKIE" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "research-agent",
    "input": "And what about the enforcement timeline?",
    "thread_id": "thr_…"
  }'

When thread_id resolves to a real thread in this workspace, the prior runs' user/assistant turns are replayed from their RunEvent logs so the model sees the full history. An unknown thread_id falls through to a fresh thread rather than erroring. The agent loop runs asynchronously; you watch progress via the stream or the read endpoint below.

The body is validated as { agent: string, input: string (1–10000 chars), thread_id?: string | null }.

Read a run

GET /api/v1/sessions/{id} returns the run metadata plus its full event log inline, ordered by sequence.

curl https://platform.groupany.ai/api/v1/sessions/run_… \
  -b "next-auth.session-token=$COOKIE"
{
  "run": {
    "id": "run_…",
    "status": "completed",
    "snapshot": { "skill": "harmony://…", "agent": "harmony://…", "hooks": [] },
    "projection": { "status": "completed", "cost_usd": 0.0312, "tool_call_count": 3, "…": "…" },
    "started_at": "2026-05-28T19:02:11.000Z",
    "finalized_at": "2026-05-28T19:02:48.000Z",
    "last_event_at": "2026-05-28T19:02:48.000Z",
    "agent": { "name": "research-agent", "version": 4, "skill": { "name": "research-a-topic", "version": "0.3.1" } }
  },
  "events": [
    { "id": "evt_…", "sequence": 1, "type": "session.started", "payload": { "…": "…" }, "created_at": "…" }
  ]
}

Stream a run

GET /api/v1/sessions/{id}/stream is a Server-Sent Events feed. It flushes every existing event first, then polls for new ones until the run finalizes (or the client disconnects). Each SSE frame carries the event type on the event: line and a { sequence, payload, createdAt } object on the data: line; an id: line carries the event id.

curl -N https://platform.groupany.ai/api/v1/sessions/run_…/stream \
  -b "next-auth.session-token=$COOKIE"
id: evt_…
event: user.message
data: {"sequence":2,"payload":{"type":"user.message","text":"What changed…"},"createdAt":"…"}

id: evt_…
event: assistant.partial
data: {"sequence":7,"payload":{"type":"assistant.partial","text":" Act","total_text":"The EU AI Act"},"createdAt":"…"}

event: end
data: {}

A terminal event: end frame is sent once the run finalizes. An event: error frame is emitted if the stream itself faults.

Deployed-agent chat (proxy)

For agents running in their own deployed runtime there's a proxy pair under /api/v1/workspaces/{slug}/deployments/{id}/sessions. POST resolves/creates the thread, seeds the runtime with prior conversation, and forwards the turn to the runtime's /v1/sessions. GET streams the runtime's SSE back to the browser while teeing recognised events into a local Harmony Run, so deployed-agent runs land on Sessions / Threads and roll their cost up exactly like in-platform runs. Only event types Harmony knows are mirrored; anything else is dropped — the runtime owns the canonical feed, the local log is a best-effort mirror.

Event types

Every event is one member of the RunEventPayload union (src/lib/events.ts). This is the source of truth; the projection and all renderers are derived from it.

TypePayload
session.started{ snapshot: { skill, agent, tool_catalog?, hooks[] } }
user.message{ text } — the human turn; always emitted so a Thread can be rehydrated from RunEvents alone
assistant.partial{ text, total_text } — buffered streaming (~150ms); total_text is cumulative for the iteration
llm.tokens{ model, input, output, cached?, cost_usd, duration_ms }
tool.call{ name, call_id, args }
tool.result{ call_id, ok, result_size, attachment_ref?, duration_ms, error?, render_kind?, render_data? }
hook.fired{ name, phase, status, output_excerpt?, duration_ms }
ui.token{ frame_id, component, props, partial, terminal }
attachment.added{ ref, kind, bytes }
cost.accrued{ cost_usd, source }
status.changed{ from, to, reason? }
session.completed{ final_message_ref?, ok }
session.failed{ error_code, error_message }
session.budget_exceeded{ cap_kind, limit, actual }
credential.fetched{ binding_name, scope, ttl_seconds }
credential.proxy_injected{ tool_call_id, binding_name }

render_kind / render_data on tool.result are the typed-renderer hints (Decision 0020): the client picks a matching renderer from a registry, falling back to a generic JSON card when the kind is unknown or absent.

Projection

Runs are append-only event logs; Run.projection is the derived rollup (status, total cost_usd, durations, tool/LLM/hook counts, per-model breakdown, last event, final message ref, error). It is never written by hand.

The projection is maintained by a per-run, advisory-locked incremental fold inside the same transaction that appends the event: each appendEvent takes pg_advisory_xact_lock(hashtext(runId)) to serialise concurrent appends, folds the single new event onto the persisted projection (applyEvent), and writes it back — an O(1) steady-state path. A full replay (project) runs only when the row's projectionVersion differs from PROJECTION_VERSION (a logic change) or for rows that pre-date versioning. This is the behaviour after the 7a hardening; before it, the fold was not locked.

To add a new event type: extend the RunEventPayload union, handle it in applyEvent (the exhaustiveness check forces this at compile time), bump PROJECTION_VERSION, and let the next append replay affected runs.

finalizeRun and appendEvent are internal server functions in src/lib/runs.ts, not HTTP endpoints. Runs finalize when a terminal event (session.completed / session.failed / session.budget_exceeded) is appended by the runner or the deploy proxy.