Aomi SDK Patterns
These patterns come from the SDK examples (sdk/examples/app-template-http), current SDK source, and inspected public apps in aomi-sdk/apps. Current SDK is v3.0.1, Rust 2024 edition.
Canonical Layout
Use this split unless there is a strong reason not to:
apps/my-app/
├─ Cargo.toml
└─ src/
├─ lib.rs
├─ client.rs
└─ tool.rslib.rs: manifest, preamble,dyn_aomi_app!client.rs: app struct, HTTP client, auth, models, helperstool.rs:DynAomiToolimpls and user-facing tool surface
Cargo.toml must declare edition = "2024", crate-type = ["cdylib"], and depend on aomi-sdk = { workspace = true }. The host enforces an exact-match SDK version gate: after bumping sdk/Cargo.toml, all apps must be rebuilt — see docs/sdk-version-compatibility.md.
Minimal Manifest Shape
use aomi_sdk::*;
mod client;
mod tool;
const PREAMBLE: &str = r#"## Role
You are ...
"#;
dyn_aomi_app!(
app = client::MyApp,
name = "my-app",
version = "0.1.0",
preamble = PREAMBLE,
tools = [
client::SearchThing,
client::GetThing,
],
namespaces = ["evm-core"]
);Keep lib.rs small. The manifest should be easy to audit at a glance.
The namespaces field is required. Current canonical host namespaces are explicit strings:
namespaces = ["evm-core"]for most EVM apps and generated OpenAPI apps. This injects the current EVM host tools such asencode_and_call,stage_tx,simulate_batch,commit_txs, andevm_commit_message.namespaces = ["svm-reads", "svm-ix-broadcast", "svm-tx-broadcast"]for Solana apps that need SVM read/stage/commit host tools.namespaces = []only for apps that should receive no host namespace at all.
Do not copy the old "common" namespace into new apps. Current SDK docs note that legacy namespace was removed in host iter-39; the loader skips unknown namespaces.
The macro generates the C ABI exports (aomi_create, aomi_manifest, aomi_async_tool_start, aomi_dyn_exec_poll, etc.) and embeds the SDK version stamp the host uses for compatibility checks.
What The Real Apps Show
sdk/examples/app-template-http
Use as the default baseline for read-only HTTP APIs.
- Simple
reqwest::blockingclient - Clean typed args
- Small tool surface
- Straightforward JSON normalization
apps/x
Use this pattern when the upstream API:
- needs an env-backed API key
- has a wrapper response envelope
- benefits from normalized data models and formatting helpers
Notable conventions:
- auth env vars live in
client.rs - logical API failures are normalized before reaching tools
- tools return concise, model-friendly JSON
apps/polymarket
Use this pattern when the app needs:
- multiple upstream API surfaces
- dynamic preamble context such as exact current date
- intent resolution before execution
- multi-step flows with explicit user confirmation
Notable conventions:
- preamble explains exact flow order
- tool surface separates search, details, intent resolution, preview, and submit
- results include next-step hints without hiding uncertainty
apps/khalani and apps/polymarket
Use this pattern when execution must hand off to host wallet tools.
Notable conventions:
- app tools never send the wallet request directly
- build/submit tools return
ToolReturn::with_routes(value, [...])envelopes — never prose-based hints - routes use
RouteStep::on_return("evm_commit_message", typed_data).bind_as("signature").prompt(...)for typed-message signing, orRouteStep::on_return("commit_txs", args)for EVM transaction commit, to declare what tool the host should call next, what args to pass, and what alias to bind the result under - subsequent routes use
RouteStep::on_bound_event("submit_*", template, "signature")to wait for the bound alias before continuing - preamble tells the model to preserve exact host args and let the runtime resolve the route — the runtime never parses prose
apps/geckoterminal
Use this pattern for the current OpenAPI/progenitor app-local pipeline.
Notable conventions:
openapi.yamlis the editable source spec.openapi.preprocessed.yamlis a regenerated debug artifact fromgen-client; inspect it when progenitor fails, but do not edit it.src/client/is generated by progenitor and wrapped by a hand-curatedtool.rs.Cargo.tomlincludesprogenitor-client, matchingreqwest0.13, and any dependency markers detected from the generated client.gen-toolstubs one tool peroperationId; the shipped app should curate those stubs into user-intent tools and a real preamble.
Executable product integrations
When the source material is mostly SDK docs, example repos, runtime notes, or architecture docs, first check whether it exposes or produces a client-facing interface such as:
- REST or GraphQL
- JSON-RPC
- gRPC
- webhooks
- a stable CLI request/response contract
- a local example service or reference node
If such a surface exists:
- build the app against that executable interface
- treat the SDK, example repo, and docs as implementation references
- expose user-useful operations against the real service, not just summaries of the docs
- validate with at least one real call when possible
Builder-oriented fallbacks
Use a builder-oriented shape only when the source material is mostly:
- SDK documentation
- example repositories
- architecture notes
- runtime / RPC references
- config files and quickstarts
In that case:
- do not pretend there is a public swap, quote, or portfolio API unless the source really documents one
- do not hide the absence of a real integration target
- prefer tools such as
list_*_resources,get_*_overview,get_*_quickstart,get_*_rpc_surface, orget_*_network_defaults - make the preamble explicit that the app is a builder assistant, not an end-user trading agent
- say clearly what would be needed to upgrade the app into a real client later, such as a base URL, running example service, or customer endpoint
Tool Authoring Checklist
Every tool should answer these:
- What user intent does it serve?
- What exact name should the model call?
- What fields does the model need to provide?
- What result shape will be easiest for the model to reason over?
- If the upstream API is inconsistent, where will normalization happen?
Prefer names like:
search_*get_*list_*resolve_*build_*submit_*
Client Conventions
Keep these in client.rs whenever possible:
- base URLs
- auth headers
- shared request helpers
- response envelopes
- normalization helpers
- typed upstream models
Prefer short actionable errors such as:
X_API_KEY environment variable not setGamma API error 404: ...Failed to parse markets: ...
Validation Commands
Inside aomi-sdk, the standard loop is:
cargo run -p aomi-sdk --features cli --bin aomi-build -- init my-app
cargo run -p aomi-sdk --features cli --bin aomi-build -- compile --app my-appFor OpenAPI- or URL-driven scaffolds, use the staged pipeline or one-shot orchestrator:
cargo run -p aomi-sdk --features cli --bin aomi-build -- gen-specs geckoterminal --from-url https://api.geckoterminal.com/docs/v2/swagger.json
cargo run -p aomi-sdk --features cli --bin aomi-build -- gen-client geckoterminal --force
cargo run -p aomi-sdk --features cli --bin aomi-build -- gen-tool geckoterminal --all --force
cargo run -p aomi-sdk --features cli --bin aomi-build -- new-app geckoterminal --from-url https://api.geckoterminal.com/docs/v2/swagger.jsonDefault OpenAPI mode is app-local: apps/<platform>/openapi.yaml, apps/<platform>/src/client/, and apps/<platform>/src/tool.rs. Use --shared only for large reusable providers; then specs live under ext/specs/ and clients under ext/src/.
compile accepts --release and --target <triple>. It validates the manifest, codesigns the cdylib on macOS, and validates the produced plugin file.
One caveat from practice:
- Current
aomi-build compilescans tracked app manifests and falls back to the apps directory, so a brand-new app is less likely to be skipped than in older xtask builds. - Use
cargo build --manifest-path apps/my-app/Cargo.tomlfor an immediate crate-level compile check when debugging package errors. - Apps with
[package.metadata.aomi.skip]set are excluded intentionally — useful for in-progress crates.
For generated APIs:
aomi-build test-schema <platform>runs a Schemathesis smoke against the live API. It is GET-only by default; pass--writeonly for sandbox/testnet APIs where fuzzing writes is acceptable.aomi-build tighten-spec <platform> --in-placecan replace looseadditionalProperties: trueresponse bodies using captured JSON samples, then rerungen-client --force.
For focused logic tests, use the SDK test helpers:
use aomi_sdk::testing::{TestCtxBuilder, run_tool, run_async_tool};
let ctx = TestCtxBuilder::new("search_thing").build();
let result = run_tool::<MyTool>(&MyApp, json!({"query": "eth"}), ctx)?;
// result is a ToolReturn — bare-value tools have empty routes; route-returning
// tools include the structured RouteStep list under result.routesrun_tool returns the full ToolReturn (handy for asserting routes alongside the JSON payload). run_async_tool returns (updates, terminal) so you can assert intermediate emit payloads as well as the final complete payload.