Documentation
¶
Overview ¶
Package mobileagent is the UI-neutral session boundary for native mobile hosts. Android (Kotlin) and a future iOS (Swift) host supply the workspace, provider stream, tool registry and authorization gate; this package owns one conversation, one run at a time, cancellation, and an ordered JSON-encodable event queue.
It deliberately imports neither gui/appsession nor any desktop browser, terminal or Computer Use package. A host that wants the Android tool catalog builds it with internal/androidagent and passes the resulting Batch config.
Index ¶
- Constants
- type Config
- type Event
- type Session
- func (s *Session) Cancel()
- func (s *Session) Close() error
- func (s *Session) Permissions() *permissions.State
- func (s *Session) Poll(max int) []Event
- func (s *Session) PollJSON(max int) (string, error)
- func (s *Session) Running() bool
- func (s *Session) Snapshot() Snapshot
- func (s *Session) SnapshotJSON() (string, error)
- func (s *Session) Start(prompt string) error
- func (s *Session) Workspace() string
- type Snapshot
Constants ¶
const ( EventRunStart = "run_start" EventText = "text" EventThinking = "thinking" EventToolStart = "tool_start" EventToolUpdate = "tool_update" EventToolEnd = "tool_end" EventContextUsage = "context_usage" EventRunEnd = "run_end" )
Event types carried across the host boundary.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Workspace is the host-selected project directory. Tools receive their own
// roots from the host; this path is validated and recorded for the host.
Workspace string
Model string
Provider string
// Stream produces the provider stream. A mobile host normally wires the
// real provider; tests use a scripted one.
Stream provider.StreamFn
// APIKey is the static fallback. GetAPIKey, when set, is consulted per
// request and wins over APIKey, which is how a host refreshes short-lived
// credentials without rebuilding the session.
APIKey string
GetAPIKey func(context.Context, string) string
SystemPrompt string
// History restores an earlier conversation. The slice is copied.
History agentcore.MessageList
// Tools is the model-visible catalog. When Batch.Registry is set, the
// registry's tools replace this field.
Tools []agentcore.AgentTool
Batch agenttool.BatchConfig
// Permissions is the live approval mode shared with the tool set. Nil
// selects auto mode for hosts that inspect it; the gate is still
// Batch.BeforeToolCall.
Permissions *permissions.State
ThinkingLevel agentcore.ThinkingLevel
ContextWindow int
Compaction compaction.CompactionSettings
// Checkpoint is the loop's mid-run persistence seam. It runs on the loop
// goroutine and must not block on user input.
Checkpoint func(context.Context, *agentcore.AgentContext, bool)
// ObserveEvent is optional host telemetry. It runs on the loop goroutine
// and must not block; it receives every loop event in order.
ObserveEvent func(agentcore.AgentEvent)
// OnRunEnd is optional persistence/telemetry for the final conversation.
// It runs on the session goroutine after the loop has stopped and before
// run_end is published, so a host can save the completed turn before the
// next run may start.
OnRunEnd func(agentcore.MessageList)
SessionID string
EventBuffer int
}
Config is supplied by the mobile host, never by the model. Workspace, Stream and Model are required. Tools and Batch must describe the same catalog; when Registry is set, Tools is replaced with the registry's list so the model cannot be offered a tool the executor does not know. A non-empty tool catalog requires an authorization gate (Batch.BeforeToolCall): the session never manufactures an unconfined-execution grant.
type Event ¶
type Event struct {
Seq uint64 `json:"seq"`
RunID string `json:"runId,omitempty"`
Type string `json:"type"`
Text string `json:"text,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
ContextTokens int `json:"contextTokens,omitempty"`
ContextWindow int `json:"contextWindow,omitempty"`
Details json.RawMessage `json:"details,omitempty"`
IsError bool `json:"isError,omitempty"`
StopReason string `json:"stopReason,omitempty"`
Error string `json:"error,omitempty"`
Cancelled bool `json:"cancelled,omitempty"`
}
Event is one ordered notification. Seq is assigned by the session and increases monotonically for its lifetime, so a host can detect a missed event. Type selects which of the remaining fields are meaningful. All fields are JSON-safe so a JNI/Objective-C bridge can forward the marshaled value without inspecting Go types.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session owns one mobile conversation. It is safe for concurrent use; at most one run is active at a time. Poll (or PollJSON) is the intended bridge: a host drains events on its own thread rather than blocking a UI thread inside a JNI callback.
func (*Session) Cancel ¶
func (s *Session) Cancel()
Cancel asks the active run to stop. It is a no-op when idle. The run_end event reports Cancelled once the loop has drained.
func (*Session) Close ¶
Close cancels any active run, waits for it to drain, and makes the session unusable. It does not close host-owned tools; the host remains responsible for the tool set it built.
func (*Session) Permissions ¶
func (s *Session) Permissions() *permissions.State
Permissions returns the live approval state the host shares with its tools.
func (*Session) PollJSON ¶
PollJSON is Poll for a bridge that forwards JSON instead of translating Go values. An empty queue is "[]", never "".
func (*Session) Running ¶
Running reports whether a run is active (including its final event not yet polled).
func (*Session) SnapshotJSON ¶
SnapshotJSON is Snapshot for a JSON bridge.
type Snapshot ¶
type Snapshot struct {
Running bool `json:"running"`
RunID string `json:"runId,omitempty"`
Seq uint64 `json:"seq"`
Pending int `json:"pending"`
Messages agentcore.MessageList `json:"messages"`
}
Snapshot is the state a host reads after a missed event or a view rebuild. Messages is a shallow copy of the conversation; message values are immutable once appended by the loop.