Documentation
¶
Overview ¶
Package logos provides a reusable stateless agent loop.
Run() executes one agent loop iteration: prompt → LLM → tool calls → response. The caller provides conversation history, a system prompt, tools, and an optional sandbox env. No persistence — the caller receives StepMessages and handles storage.
Plane: shared
Index ¶
- Constants
- func BuildSystemPrompt(data PromptData) (string, error)
- func ContainsToolCallHallucination(text string) bool
- type AllowedPath
- type Callbacks
- type Command
- type CommandDoc
- type CommandRunner
- type Config
- type PromptData
- type RunRequest
- type RunResponse
- type RunResult
- type StepMessage
- type StepRole
Constants ¶
const CommandPrefix = "§ "
CommandPrefix is the prefix for agent commands in LLM output.
const DefaultMaxSteps = 30
DefaultMaxSteps is the fallback max steps when Config.MaxSteps is 0.
const DefaultMaxTokens = 16384
DefaultMaxTokens is the fallback max output tokens when Config.MaxTokens is 0.
const MaxHallucinationRetries = 3
MaxHallucinationRetries is the maximum number of tool call hallucination retries before Run() returns an error.
Variables ¶
This section is empty.
Functions ¶
func BuildSystemPrompt ¶
func BuildSystemPrompt(data PromptData) (string, error)
BuildSystemPrompt renders the default system prompt with runtime context. The result is the base prompt — consumers append their own instructions after this.
func ContainsToolCallHallucination ¶ added in v0.8.0
ContainsToolCallHallucination returns true if text contains tool call patterns produced by models that hallucinate structured formats — XML tags (e.g. <tool_call>) or bracket delimiters (e.g. [TOOL_CALL]...[/TOOL_CALL]). Standalone utility — internal detection is handled by streamFilter during streaming.
Types ¶
type AllowedPath ¶ added in v0.3.0
type AllowedPath = client.AllowedPath
AllowedPath specifies a filesystem path allowed in the sandbox.
type Callbacks ¶
type Callbacks struct {
// OnDelta is called with each text delta as the LLM streams its response.
OnDelta func(text string)
// OnCommandStart is called when a § command is detected, before execution.
OnCommandStart func(command string)
// OnCommandResult is called after a command executes with the command string,
// raw combined stdout+stderr output (no exit code suffix), and the exit code.
// exitCode is -1 if the sandbox itself failed to execute the command (temenos
// transport error), in which case output contains the error description.
OnCommandResult func(command string, output string, exitCode int)
// OnRetry is called when a tool call hallucination (XML or bracket) is detected
// and an "unprocessed" directive is injected. reason is "tool_call".
OnRetry func(reason string, step int)
}
Callbacks holds optional streaming callbacks for the agent loop. All fields are nil-safe — unset callbacks are simply not called.
type Command ¶
type Command struct {
Raw string // full original line (e.g. "§ ls -la")
Args string // everything after "§ " (e.g. "ls -la")
}
Command represents a parsed § command from assistant output.
func ParseCommand ¶
ParseCommand checks if a line is a § command. Returns the command and true if the line starts with "§ ". Returns zero Command and false otherwise.
type CommandDoc ¶ added in v0.9.0
type CommandDoc struct {
Name string // command name, e.g. "url", "web", "rg"
Summary string // one-line description shown under the heading
Help string // full help text (flags, examples, caveats)
}
CommandDoc describes a command available to the agent. Callers provide these to control which commands appear in the system prompt.
type CommandRunner ¶
type CommandRunner interface {
Run(ctx context.Context, req RunRequest) (*RunResponse, error)
}
CommandRunner executes a sandboxed command and returns the result. *client.Client satisfies this interface automatically.
func NewClient ¶ added in v0.3.0
func NewClient(addr string) (CommandRunner, error)
NewClient creates a CommandRunner connected to a temenos daemon. addr formats:
- Empty string: resolve from TEMENOS_LISTEN_ADDR → TEMENOS_SOCKET_PATH → default socket
- Starts with "/" or ".": unix socket path
- Starts with "http://": HTTP base URL (TCP)
- Otherwise (e.g. ":8081", "localhost:8081"): TCP
type Config ¶
type Config struct {
Provider fantasy.Provider
Model string
SystemPrompt string
MaxSteps int // 0 means use default (DefaultMaxSteps)
MaxTokens int // 0 means use default (DefaultMaxTokens)
Temenos CommandRunner
SandboxEnv map[string]string // env vars passed to temenos per-request
// AllowedPaths lists filesystem paths accessible during command execution.
// Path validation (non-empty, absolute) is enforced by the temenos daemon.
AllowedPaths []AllowedPath
}
Config holds everything needed to run one agent loop iteration.
type PromptData ¶
type PromptData struct {
WorkingDir string
Platform string
Date string
Commands []CommandDoc // caller-provided command documentation
}
PromptData holds the runtime context used to render the default system prompt.
type RunRequest ¶ added in v0.3.0
type RunRequest = client.RunRequest
RunRequest is the request payload for sandboxed command execution.
type RunResponse ¶ added in v0.3.0
type RunResponse = client.RunResponse
RunResponse is the response from sandboxed command execution.
type RunResult ¶
type RunResult struct {
Response string // final text response (accumulated assistant text)
Steps []StepMessage // all messages generated (for persistence by caller)
}
RunResult contains the agent's output after a loop completes.
type StepMessage ¶
type StepMessage struct {
Role StepRole
Content string
Reasoning string // thinking block text (empty if no reasoning)
ReasoningSignature string // provider signature for round-trip
Timestamp time.Time
}
StepMessage represents one message generated during the agent loop.