Expand description
§graphrt-ffi
Embedding API for apps written in Kotlin (Android), Swift (iOS / macOS), Python and other languages supported by UniFFI.
The surface is deliberately small and JSON-string based so it stays stable across languages and versions:
Runtime::new(config_json) // providers, env, limits
.register_wasm_plugin(bytes) // optional, sandboxed plugins
.register_tool_provider(name, tools, provider) // native tools of the app
.load_workflow(yaml_or_json) -> WorkflowHandle
WorkflowHandle.start(inputs_json, sys_json, run_listener) -> RunHandle // typed events
WorkflowHandle.resume_paused(paused_run, secrets_json, run_listener) -> RunHandle
WorkflowHandle.run(inputs_json, sys_json, listener) -> RunHandle // raw JSON events
WorkflowHandle.resume(snapshot_json, inputs_json, secrets_json, listener) -> RunHandle
RunHandle.abort(reason) / pause(reason) / wait_json(timeout_ms)
Runtime.set_credential_provider(provider, callback) // keys from Keychain / Keystore
Runtime.install_skill / list_lessons / decide_lesson ... // features `skills`, `learning`
validate_ui_block(json) // feature `ui`Runs execute on a Tokio runtime owned by Runtime; listener callbacks are
invoked from its worker threads, never from the caller’s thread. Nothing in
this crate spawns processes, so every feature is usable on iOS and Android.
Every exported function and type exists whatever the cargo features: a
capability that is compiled out fails with GraphrtError::Unsupported, so
one set of generated bindings fits every build.
§Config JSON
{
"providers": { "OPENAI_API_KEY": "sk-...", "OLLAMA_HOST": "http://10.0.2.2:11434" },
"env": { "CRM_TOKEN": "..." },
"limits": { "max_steps": 10000, "max_duration_ms": 60000, "default_node_timeout_ms": 30000 },
"allow_private_network": false,
"knowledge": { "...": "knowledge-retrieval datasets (see graphrt-rag)" },
"mcp_servers": { "mcpServers": { "docs": { "url": "https://..." } } },
"wasm": { "fuel": 1000000000, "memory_bytes": 67108864 },
"credentials": {
"openai": { "source": "external" },
"proxy": { "source": "external", "kind": "openai", "base_url": "https://llm-proxy.example.com/v1" },
"anthropic": { "source": "token_broker", "url": "https://api.example.com/llm-token", "app_auth": "external" }
},
"skills_dir": "/data/user/0/com.example/files/graphrt/skills",
"learning_dir": "/data/user/0/com.example/files/graphrt/learning",
"workspace": { "dir": "/data/user/0/com.example/files/graphrt/workspace", "read_only": false },
"scripted_models": { "demo": [{ "text": "Hello from a scripted model." }] }
}skills_dir (feature skills), learning_dir (feature learning) and
workspace (feature files, the agents’ files tools) must be
directories in the app’s own storage. scripted_models (feature
scripted-llm) registers offline model providers for tests and previews.
credentials declares providers whose keys never appear in the config: an
external provider asks the CredentialProvider registered with
Runtime::set_credential_provider; a token_broker provider fetches
short-lived tokens from your backend. See docs/credentials.md.
providers uses the same variable names as the CLI’s environment
(OPENAI_API_KEY, OPENAI_BASE_URL, ANTHROPIC_API_KEY, OLLAMA_HOST,
GRAPHRT_OPENAI_COMPAT_<NAME>_BASE_URL…). env values are exposed to
workflows only for the env variables a workflow declares.
Structs§
- Approval
Request - One node of a paused run that waits for an answer.
- Credential
Record - A credential returned by the host.
- Form
Action - A button of a
human-inputform. - Form
Field - A field of a
human-inputform. - Host
Tool Call - One call of a tool, as the app receives it.
- Host
Tool Result - What a tool returns.
- Host
Tool Spec - A tool the app offers to agents.
- Lesson
Info - A lesson of an agent.
- Lesson
Proposal - A lesson proposed from feedback on a run.
- Paused
Run - A paused run: its requests, the answers given so far and its snapshot.
- Pending
Tool Call - A tool call waiting for approval.
- RunHandle
- Controls one run.
- RunResult
- The result of a run that did not pause.
- Runtime
- A configured runtime: node registry, host services and a thread pool. Create one per app and share it.
- Skill
Grant - A tool granted to a skill.
- Skill
Info - An installed skill.
- Skill
Install - What to install.
- UiBlock
- A UI block an agent produced, checked against its schema.
- UniFfi
Trait Vtable Event Listener - Workflow
Handle - A compiled workflow, ready to run any number of times concurrently.
Enums§
- Graphrt
Error - Errors surfaced to foreign code as exceptions.
- Lesson
Decision - A decision about a lesson.
- Lesson
Kind - What kind of thing a lesson is.
- Lesson
Status - Where a lesson is in its life.
- Request
Kind - What a request asks for.
- RunEvent
- An event of a run.
- RunStatus
- How a run ended.
- Tool
Call Error - An error a tool reports. The model receives
reasonand may try again.
Traits§
- Credential
Provider - Supplies model credentials. Implemented in the host language.
- Event
Listener - Receives the events of one run. Implemented in the host language.
- RunListener
- Receives the typed events of one run. Implemented in the host language.
- Tool
Provider - Native tools implemented by the app.
Functions§
- graphrt_
version - Version of the embedded runtime.
- uniffi_
graphrt_ ffi_ fn_ init_ callback_ vtable_ eventlistener - validate_
ui_ block - Check a UI block (
{"$ui": "chart", "version": 1, ...}) against its schema, for blocks an app receives outside a run (stored messages, a server).