Porting a multi-agent sim framework to Anna App — questions before the hackathon

Hi anna team,

I’m Qingyu, building Truman World — an open-source multi-agent simulation framework where users act as a “director” rather than a “scriptwriter”: you observe autonomous agents with persistent state and event-driven behaviors, then intervene by creating conditions (weather changes, new arrivals, resource shifts) rather than issuing direct commands.

It’s built on a custom Python agent runtime with a pluggable LLM backend architecture — currently supports Claude Code CLI’s Agent SDK (claude-agent-sdk) and LangGraph (via LangChain) as interchangeable cognition backends for agent decision-making, plus a rule-based fallback. We’re hoping to swap the LLM backend entirely for Anna’s sampling/createMessage reverse RPC (same prompt engineering, zero API cost).

What I’m building

Adapting one workflow from Truman World into an Anna App:

  • Executa plugin (Python): world state engine + tick orchestration + action resolution + director observation layer (~60% pure Python, no external deps)
  • Sampling/createMessage: replace Claude SDK calls for agent decision-making with Anna’s reverse RPC (zero API cost)
  • SKILL.md: declarative “director coach” — how to observe, when to intervene, frame interventions as conditions not commands
  • UI Bundle: custom panel with world view, timeline, agent inspector, director console (play/pause/tick + event injection)

Planned architecture: hybrid — rich sim view in bundle, chat as director control layer.


Questions

1. Sampling stability for multi-agent workflows

For a hackathon demo where every agent tick needs a sampling.createMessage call (see also #71, #83, #63):

  • Q1: Is there a recommended retry pattern for sampling token-expiry errors? Or a way to pre-validate/refresh tokens before invoking?
  • Q2: Will the hackathon runtime build have stable sampling, or should we design a fallback path (e.g., skip LLM decision → use rule-based action)?
  • Q3: Any timeline on JSON Schema / response_format support for sampling? Prompt-only JSON enforcement adds meaningful retry overhead for structured agent actions.

2. UI Bundle capabilities & CSP

  • Q4: Full default CSP policy for bundles? Focus Flow overrides img-src/font-src/style-src/script-src — what about connect-src/frame-src/worker-src/child-src?
  • Q5: Can bundles load external CDN libs (Phaser CDN for 2D canvas, Chart.js) via external_origins? Or must all JS be local?
  • Q6: Does the bundle runtime support <canvas> / WebGL / Web Workers? Deciding between 2D canvas vs text-based world viz.
  • Q7: Memory or payload size limits for bundles? Our world state (5 agents × 50 ticks) could reach a few MB serialized.

3. Multi-agent tick architecture

One tick = advance state → resolve events → per agent: sampling.createMessage (LLM decision) → execute → update state. With 5 agents that’s 5 sequential sampling calls per tick (see also #69, #68):

  • Q8: Should a multi-agent tick be: (a) one big invoke with internal loop (timeout risk), (b) one invoke per agent (5x user triggers), or (c) agent.session with streaming? Which have you seen work best for multi-step tool workflows?
  • Q9: For “run N ticks automatically” with no cron available — is manual step-per-click the recommended UX? Any pattern where plugin work survives beyond a single invoke?

4. Tool ID & local dev

  • Q10: Can I use placeholder/unminted tool IDs during local anna-app dev (e.g. dev:truman-sim) and mint real IDs only before platform submission? (see also #76)
  • Q11: Focus Flow uses "bundled:focus-session" IDs in required_executas. Is bundled: for internally-bundled executas vs tool-{handle}-{slug}-{uniq} for standalone published tools? When to use which?

5. Reference & review

  • Q12: Any published Apps or community repos with similar “rich dashboard + persistent state + non-chatbot-primary” patterns?

Thanks in advance — happy to share repo details if helpful.

Hi Qingyu! :waving_hand:

First off — we absolutely love Truman World. :heart_eyes: The “director, not scriptwriter” framing (intervene by creating conditions, not commands) is exactly the kind of emergent, non-chatbot-primary experience we hoped people would build on Anna. The architecture you sketched (Executa world engine + sampling for cognition + SKILL.md director coach + custom bundle panel) maps onto the platform so naturally it almost feels like the platform was designed for it. This is genuinely one of the most exciting porting projects we’ve seen on this forum.

And let us say this upfront: we’d love to actively support you through the entire launch :handshake: — architecture/manifest reviews, debugging help during the hackathon, fast-tracked answers here on the forum, and yes, platform-level upgrades where Truman World hits a real limitation. Several recent platform features (token renewal, responseFormat — see below) came directly from developer threads like this one. If your sim needs something the platform doesn’t do yet, tell us — multi-agent simulation is a direction we want the platform to grow toward, and you’re the perfect design partner for it. :rocket:

Now, your questions one by one:


1. Sampling stability :brain:

Q1 (token expiry / retry) — :white_check_mark: Solved. Token expiry inside long invokes was a real bug and it’s fixed end-to-end with automatic token renewal:

  • The host now proactively renews the sampling token when it has <90s of life left, and reactively renews + retries once if a call hits SAMPLING_TOKEN_EXPIRED.
  • This is entirely host-side — your plugin doesn’t need any token-handling code. You should never see expiry errors anymore, even in invokes that make many sequential sampling calls.
  • Recommended plugin-side retry: only retry on -32003 (provider error) / -32005 (timeout) with bounded backoff (e.g. 2 attempts). Don’t retry -32001/-32002/-32006/-32007 — those are auth/quota and won’t heal.

Q2 (hackathon stability) — :white_check_mark: Solved, with a caveat. The two root causes behind the “sampling unstable” reports (#83) — missing token minting on the iframe tools.invoke path, and the expiry issue above — are both fixed in the current runtime. That said, your rule-based fallback is still a great idea :light_bulb: — not for platform stability, but because users can decline the sampling grant or hit their quota. Graceful degradation to rule-based actions makes your sim resilient and demos well. (And if you hit any sampling flakiness during the hackathon, ping us directly — we’ll prioritize it.)

Q3 (JSON Schema / response_format) — :white_check_mark: Shipped! :tada: This was forum request #63 and it’s live — a perfect example of forum-driven platform upgrades. sampling/createMessage now accepts an optional responseFormat:

{
  "responseFormat": {
    "type": "json_schema",
    "json_schema": {
      "name": "agent_action",
      "strict": true,
      "schema": { "type": "object", "properties": { "action": {"type": "string"} }, "required": ["action"], "additionalProperties": false }
    }
  },
  "onUnsupported": "json_object"
}
  • L1 json_object (JSON mode, broadly compatible) and L2 json_schema (strict schema).
  • Capability negotiation instead of silent downgrade: if the selected model doesn’t support the requested level you get an explicit -32010, unless you opt into onUnsupported: "json_object" / "text".
  • The response is still content.text (parse it yourself); the host adds _meta.responseFormat.structuredValid so you know whether it parsed.
  • Schema limits: ≤32KB serialized, depth ≤8, ≤512 nodes.
  • Supported in all three SDKs (Python/Node/Go) and the local anna-app dev harness (CLI ≥ v0.1.29 includes structured-output emulation, plus a flag to simulate an unsupported model so you can test your fallback branches locally).

For structured agent actions this should remove your prompt-only retry overhead entirely. Perfect timing for your use case! :sparkles:


2. UI Bundle & CSP :artist_palette:

Q4 — Here’s the full default CSP for bundle iframes (the iframe runs with an opaque origin, so 'self' means the bundle’s own origin):

Directive Default
default-src 'none'
script-src 'self'
style-src 'self' 'unsafe-inline'
img-src 'self' data: blob:
font-src 'self' data:
media-src 'self' blob:
connect-src 'self'
worker-src 'self' blob:
frame-ancestors 'self'
base-uri / form-action 'self'

Overridable via ui.csp_overrides: connect-src, img-src, media-src, font-src, style-src, script-src. (frame-src/child-src are not overridable — nested iframes aren’t supported by design.) Also note: declaring ui.host_api.image or upload auto-injects the object-storage origins into img-src/connect-src for you.

Q5 (CDN libs) — possible, but vendor locally instead. external_origins auto-extends connect-src + img-src (data fetching / images), and you can whitelist a CDN in script-src via csp_overrides (https-only, no wildcards). But our strong recommendation: bundle Phaser/Chart.js locally. The bundle limit is generous (see Q7), local assets are faster, work offline, and make review much smoother. :package:

Q6 (canvas / WebGL / Workers) — :white_check_mark: all supported. The bundle is a real iframe — <canvas> 2D and WebGL just work, Web Workers are allowed by the default CSP (worker-src 'self' blob:), and even WASM is an allowed content type. A 2D canvas world view sounds perfect for Truman World — go for it! :world_map:

Q7 (size limits) — current limits:

  • Bundle: 50 MB total, 2,000 files, 10 MB per file.
  • KV storage (storage/*): 256 KB per value — so don’t store the whole world state in one key. Shard it: world:meta, tick:{n}, agent:{id}:state. Tick-per-key also gives you free timeline scrubbing. :triangular_ruler:
  • Larger blobs: the storage files API handles multi-MB payloads (init/finalize upload flow) — good for full world-state snapshots/exports.
  • Stdio frames between host and plugin auto-switch to file transport above 512 KB, so big invoke results won’t break, but keeping per-invoke payloads lean (send tick deltas to the UI, not full state) is the best practice.

…and if your world state outgrows these limits in practice, that’s exactly the kind of platform-level adaptation we’re open to discussing. Tell us what you need. :hammer_and_wrench:


3. Multi-agent tick architecture :gear:

Q8 — recommended: (a) one invoke per tick, with the internal per-agent loop. This is now the sweet spot because:

  • Token renewal (Q1) removed the long-invoke failure mode.
  • Each invoke has a sampling budget of max_calls (default 8) sequential LLM calls — 5 agents/tick fits comfortably. Going much above that per invoke, split into batches. (If Truman World eventually needs more agents per tick, raising this budget for your use case is a conversation we’re happy to have — this is precisely the “platform upgrade” territory we mean. :wink:)
  • One tick = one invoke also gives you atomic state transitions: read state → 5 decisions → resolve → write state with etag (use the storage etag for optimistic concurrency).

(c) agent.session with streaming is great for the director chat layer (narrating what happened, suggesting interventions), but for deterministic tick resolution the explicit per-tick invoke keeps you in control.

Q9 — drive the loop from the bundle, not the plugin. Plugin work doesn’t survive beyond an invoke (by design — no cron yet, and a background sim burning sampling quota unattended isn’t something we’d auto-grant :grinning_face_with_smiling_eyes:). The pattern that works beautifully:

// bundle/app.js — director console
async function runTicks(n) {
  for (let i = 0; i < n && !paused; i++) {
    const result = await anna.tools.invoke(TOOL_ID, "advance_tick", { ticks: 1 });
    renderTick(result);          // stream progress into the world view
    await sleep(300);            // pacing, keeps UI responsive
  }
}

The iframe is alive the whole session, so “run 20 ticks” is just a JS loop with play/pause — which doubles as your director console UX. Each tick renders as it lands, which honestly demos better than a fire-and-forget batch. :clapper_board: Longer-horizon “background simulation” is on our radar as a future platform capability — your use case is a strong data point for prioritizing it.


4. Tool IDs & local dev :wrench:

Q10 — :white_check_mark: Yes, exactly as you hoped. During anna-app dev the tool_id in your local executa.json is just a local identifier — pick anything (truman-sim is fine). Dev mode auto-registers the executa with your account (with sampling/image/upload dev grants seeded automatically), so login → dev works end-to-end with zero pre-minting. You mint the real tool-{handle}-{slug}-{uniq} ID only when you publish.

Q11 — you’ve got it right, and here’s the rule of thumb:

  • bundled:<handle> — for executas that ship inside your app repo (declared in app.json bundled_executas). At publish, the CLI auto-publishes them and substitutes real tool IDs into the manifest; it also emits a bundle/anna-tool-ids.js sidecar exposing window.__ANNA_TOOL_IDS__ so your bundle JS never hardcodes minted IDs. This resolution also runs in anna-app dev now, so dev and prod behave identically.
  • tool-{handle}-{slug}-{uniq} — only for referencing an already-published standalone executa (yours or someone else’s).

For Truman World: your world engine ships with the app → use bundled:truman-sim. One repo, one anna-app apps publish, done. :white_check_mark:


5. References :books:

The closest existing pattern to “rich dashboard + persistent state + non-chatbot-primary” is Focus Flow (anna-app-focus-flow in the anna-executa-examples repo): custom bundle panel + bundled Python executa + KV-persisted session state + chat as a secondary control layer. Also worth a look:

  • anna-app-llm-demo — sampling patterns incl. multi-call chains (very relevant for your tick loop)
  • anna-app-executa-showcase — broad host-API coverage
  • anna-app-aps-files-demo — files/storage patterns for bigger payloads

You’d honestly be pushing this pattern further than anything published so far — which is exactly why we’re so excited about it. Truman World launching on Anna would set the bar for what a “rich sim” app looks like on the platform. :glowing_star:


TL;DR

# Status
Q1 token expiry :white_check_mark: Fixed — automatic host-side renewal
Q2 sampling stability :white_check_mark: Fixed — keep rule-based fallback for grants/quota
Q3 response_format :white_check_mark: Shipped — json_object + json_schema + local emulation
Q4 CSP :clipboard: Full policy above
Q5 CDN libs :warning: Possible via overrides — vendor locally instead
Q6 canvas/WebGL/Workers :white_check_mark: Supported
Q7 limits :triangular_ruler: 50MB bundle / 256KB per KV value — shard state per tick/agent
Q8 tick arch :light_bulb: One invoke per tick, ≤8 sampling calls each
Q9 N-tick runs :light_bulb: Bundle-driven loop = your director console
Q10 dev IDs :white_check_mark: Local IDs fine, mint at publish
Q11 bundled: vs tool- :white_check_mark: bundled: for in-repo, tool-… for published
Q12 references :books: Focus Flow + examples repo

One more time because we mean it: we really want Truman World on Anna, and we’ll be hands-on in getting it there — design review before submission, debugging during the hackathon, and platform-side changes where the sim genuinely needs them (sampling budgets, state limits, longer-horizon execution — all on the table). Share the repo whenever you’re ready and let’s make this happen. Can’t wait to direct some Truman World agents ourselves! :performing_arts::sparkles: