Skip to main content

Crate troupekit_ffi

Crate troupekit_ffi 

Source

Structs§

AgentBuilder
Builds one agent in code or from a persona TOML, as the kit builder does. Wraps the neutral AgentBuilder; every setter returns a new builder and forwards unchanged. build validates everything.
AgentHandle
A built agent: runs, starts, resumes and streams, as the kit’s BuiltAgent. Wraps the neutral AgentHandle; every method forwards unchanged. Safe to share between threads and to run concurrently.
Event
One run event, mirrored from FfiEvent. seq grows by one per event of a run; at_ms is Unix time in ms. Output only.
GraphBuilder
Builds a graph of agents and tool steps, as the kit’s Graph does. Wraps the neutral GraphBuilder; every setter returns a new builder and forwards unchanged. build validates the graph.
GraphHandle
A built graph: runs, starts, resumes and streams, as the kit’s BuiltGraph. Wraps the neutral GraphHandle; every method forwards unchanged. Safe to share between threads.
GraphResult
Result of one graph run, mirrored from GraphResult. Output and state are JSON text, as the neutral layer renders them. Output only.
HostHeader
One HTTP header, mirrored from HostHeader. Used in both directions: request headers out, reply headers back. sensitive marks a credential; every text form shows it as [redacted].
HostHttpRequest
An HTTP request for a host transport, mirrored from HostHttpRequest. The neutral layer has already checked the URL against the vendor. Input to the foreign HostTransport::send; its text forms redact the key.
HostMessage
One message of a host model request, mirrored from HostMessage. Tool calls and the tool call id are JSON and text the Rust side rendered. Input to the foreign HostModel::generate.
HostModelCaps
What a host model can do, mirrored from HostModelCaps. Returned by the foreign HostModel::capabilities and read by Rust. context_tokens is the model’s context window.
HostReply
A host model’s whole reply, mirrored from HostReply. Rust parses and validates text and tool_calls_json (native tool calls, for a model whose caps set tools); token counts feed usage.
HostRequest
A request to a host model, mirrored from HostRequest. Rust renders every field; the host passes them to its model as given. Input to the foreign HostModel::generate.
HttpSink
Where a host transport pushes the reply, wrapping the neutral sink. Input: the head once, then body chunks. Output: chunk returns false once Rust stops reading (closed, cancelled or over the cap), and the host must then stop reading and cancel the request. Created by Rust and handed to HostTransport::send.
KnowledgeConfig
Knowledge settings for an agent, mirrored from KnowledgeConfig. dir is the folder to ingest; index and store are optional paths. Input to AgentBuilder::knowledge.
MemoryConfig
Memory settings for an agent, mirrored from MemoryConfig. user and session are set by the host and keep users apart. Input to AgentBuilder::memory.
RunResult
Result of one agent run, mirrored from RunResult. output_json holds the structured output when the agent has a schema. Output only.
RunStream
The events of one run, pulled with next or pushed to a listener. Wraps the neutral RunStream; every method forwards unchanged. Created by AgentHandle::stream and GraphHandle::stream.
RuntimeSettings
Process-wide settings for initialize, mirrored from RuntimeSettings. The neutral layer checks the bounds of plan section 8 (S1 to S3). Input: worker threads, max caller string bytes, event buffer size.
TokenSink
Where a host model pushes its text deltas, wrapping the neutral sink. Input: text pieces in order. Output: none; Rust caps the total bytes. Created by Rust and handed to HostModel::generate.
Usage
Token counts and cost of a step or a run, mirrored from FfiUsage. Output only: built from the neutral value, never read back. Cost is in millionths of a US dollar.

Enums§

ErrorCode
Stable numeric code of every failure, mirrored from the neutral ErrorCode. Swift and Kotlin compare TroupekitError.code against these numbers. The numbers are fixed forever and checked by error_code_survives_conversion.
EventKind
What happened in one run event, mirrored from FfiEventKind. Lifecycle kinds are never dropped; TextDelta may be when the buffer is full (RunStream::dropped_deltas). Output only.
HostError
Error a Swift or Kotlin host callback returns; the neutral layer turns it into a tool error output, a model failure or a transport failure. Input: the foreign text as detail, named so for the same Kotlin clash. Output: the neutral HostError with that text.
Pause
Why a run paused, mirrored from FfiPause. node names the graph node; limit names the budget that ran out. Output only.
Progress
Outcome of one background window, mirrored from Progress. Done carries the answer; Pending the run id to resume next window. Output only.
TroupekitError
The one error Swift and Kotlin see: the neutral FfiError with its code as a number, so a code added later still reaches the app unchanged. Input: a neutral error. Output: Failure { code, detail, run_id }; the text is detail because a Kotlin exception field named message clashes with Throwable.message in the generated code.

Traits§

EventListener
Receives every event of a run, implemented in Swift or Kotlin. Called on a Rust worker thread, never on the caller’s thread. Input: one event. Output: none.
HostEmbedder
An embedder implemented in Swift or Kotlin, used for knowledge. embed returns one vector of dims floats per text, in order. Rust checks the shape and the batch size.
HostModel
A model implemented in Swift or Kotlin, such as an on-device model. generate pushes text deltas into sink and returns the whole reply; Rust renders the request and parses the reply.
HostTool
A tool implemented in Swift or Kotlin and called by the agent. schema_json is a JSON Schema object; call gets the arguments as JSON and returns the output text, or a HostError the model sees.
HostTransport
An HTTP stack implemented in Swift or Kotlin, used for model calls only. send calls sink.head once, then sink.chunk per body chunk, then returns; Rust has already checked the URL against the vendor.
TraceListener
Receives every trace record of a traced build or run, implemented in Swift or Kotlin: the callback form of trace_jsonl. Called on the thread that writes the record; keys are scrubbed before the call. Input: one JSON object on one line, no newline. Output: none.

Functions§

init
Sets the process-wide runtime once, before the first agent is built. Exported as initialize (freeze open question Q2). Input: the settings. Output: the neutral layer’s result, its error converted.
version
Returns the troupekit version, exported to Swift and Kotlin. Input: none. Output: the value of troupekit_ffi_core::version, passed through unchanged.