Skip to main content

TerminalAgentBuilder

Struct TerminalAgentBuilder 

Source
pub struct TerminalAgentBuilder<LLM, P, E, H = (), S = Unprepared>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static,
{ /* private fields */ }
Expand description

Builder for creating terminal-first agents.

All registered tools become IPC commands accessible via terminal. The LLM only sees the terminal tool.

S tracks whether the terminal’s tool environments are prepared (Unprepared or Prepared); shell backends are configured only before preparation.

Implementations§

Source§

impl<LLM, P, E> TerminalAgentBuilder<LLM, P, E, ()>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static,

Source

pub fn new(llm: LLM, terminal_tool: TerminalTool<P, E, Unconfigured>) -> Self

Creates a new terminal-first agent builder.

Creates the agent with only the native terminal tool; terminal controls and other registered capabilities are IPC commands accessible through terminal (registered via .tool()).

Source§

impl<LLM, P, E, H, S> TerminalAgentBuilder<LLM, P, E, H, S>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static, H: Hook,

Source

pub fn tool<T>(self, tool: T) -> Self
where T: Tool + Send + Sync + 'static, T::Arguments: DeserializeOwned + JsonSchema + Send + 'static,

Registers a tool as an IPC command accessible via terminal.

The tool becomes a terminal command with the same name. For example, WebSearchTool becomes the websearch command.

§Example
ⓘ
builder.tool(WebSearchTool::default())
// LLM can now call: terminal({ script: "websearch \"rust async\"" })
Source

pub fn definition_handler<F>( self, definition: &ToolDefinition, handler: F, ) -> Self
where F: Fn(Value) -> Pin<Box<dyn Future<Output = Result<Option<CommandPayload>, String>> + Send>> + Send + Sync + 'static,

Registers a schema-defined command on the terminal IPC bridge.

This is the dynamic counterpart to Self::tool. The command wrapper is still derived entirely from the tool definition schema, so --help, positional arguments, and validation all stay automatic.

Source

pub fn tool_with_desc<T>(self, tool: T, description: impl Into<String>) -> Self
where T: Tool + Send + Sync + 'static, T::Arguments: DeserializeOwned + JsonSchema + Send + 'static,

Registers a tool with a custom description.

Source

pub fn tool_description( self, name: impl Into<String>, description: impl Into<String>, ) -> Self

Adds a pre-configured tool description (for tools registered elsewhere).

Use this when the tool was already registered on the registry builder.

Source

pub fn system_prompt_raw(self, prompt: impl Into<String>) -> Self

Sets a custom system prompt (raw string, no template processing).

Source

pub fn persona_prompt(self, prompt: impl Into<String>) -> Self

Sets an optional persona overlay prompt.

Source

pub fn agent_kind(self, kind: AgentKind) -> Self

Sets agent kind (coding/chatbot).

Source

pub fn transcript_path(self, path: impl Into<String>) -> Self

Sets transcript path for long-memory recovery guidance.

Source

pub fn transcript(self, path: impl Into<PathBuf>) -> Self

Enables writing readable transcript entries to the given file path.

Source

pub fn system<T: Serialize>(self, value: T) -> Self

Inserts or replaces a typed persistent system block.

Source

pub fn system_named( self, tag: impl Into<String>, content: impl Into<String>, ) -> Self

Inserts or replaces a persistent system block with an explicit tag.

Source

pub fn system_text( self, tag: impl Into<String>, content: impl Into<String>, ) -> Self

Inserts or replaces a persistent system block with raw text.

Unlike system and system_named, the content is stored verbatim without any XML wrapping. This is the preferred entry point for prose system blocks (workspace descriptions, runtime metadata, environment hints) where XML structure adds tokens without providing semantic value.

Source

pub fn with_default_prompt(self) -> Self

Generates and sets the default system prompt using the built-in template.

This should be called after all tools are registered.

§Panics

Panics when no shell backend is available.

Source

pub fn hook<NH: Hook>( self, hook: NH, ) -> TerminalAgentBuilder<LLM, P, E, HCons<NH, H>, S>

Adds a hook to intercept agent operations.

Source

pub fn skill( self, name: impl Into<String>, description: impl Into<String>, ) -> Self

Adds a skill manually without loading from filesystem.

Source

pub async fn with_subagents( self, path: impl AsRef<Path>, ) -> Result<Self, AgentError>

Loads subagents and exposes the subagent directory inside the sandbox.

§Errors

Returns an error when loading subagents or creating the sandbox symlink fails.

Source

pub async fn with_subagents_readable_only( self, path: impl AsRef<Path>, ) -> Result<Self, AgentError>

Loads subagent metadata and grants read-only access to the source directory without creating a subagents symlink in the sandbox.

Use this when the runtime already mounts subagents inside the sandbox.

§Errors

Returns an error when loading subagents or registering the readable directory fails.

Source

pub fn max_iterations(self, limit: usize) -> Self

Sets the maximum number of iterations.

Source

pub fn tool_descriptions(&self) -> &[(String, String)]

Returns the list of registered tool descriptions.

Useful for dynamically building system prompts.

Source

pub fn terminal_tool_factory(&self) -> TerminalToolFactory

Returns a factory for spawning child terminal tools (for subagents).

Source

pub const fn tool_registry_mut(&mut self) -> &mut ToolRegistryBuilder

Returns a mutable reference to the tool registry builder.

Source

pub fn sandbox_dir(&self) -> Cow<'_, str>

Returns the sandbox working directory path.

Source

pub fn build(self) -> Agent<LLM, LLM, LLM, H>

Builds the agent.

The returned agent exposes terminal plus native terminal control tools. All registered IPC tools are accessible as terminal commands.

§Panics

Panics if the knowledge_and_time prompt template fails to render.

Source§

impl<LLM, P, E, H> TerminalAgentBuilder<LLM, P, E, H, Unprepared>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static, H: Hook,

Source

pub fn shell_runtime_availability( self, availability: ShellRuntimeAvailability, ) -> Self

Sets runtime shell backend availability for terminal.

Source

pub fn ssh_servers(self, servers: Vec<SshServer>) -> Self

Sets preconfigured SSH targets that can be used by terminal with ssh mode.

§Panics

Panics when the SSH server configuration is invalid.

Source

pub fn ssh_authorizer<T: SshSessionAuthorizer + 'static>( self, authorizer: Arc<T>, ) -> Self

Sets the SSH session authorizer for interactive connect/install consent prompts.

Source

pub fn container_runtime(self, runtime: ContainerShellRuntime) -> Self

Sets the container runtime for container-backed shell sessions.

Source

pub async fn initialize_tools( self, distribution: &ToolDistribution, cache_root: &Path, ) -> Result<TerminalAgentBuilder<LLM, P, E, H, Prepared>, ToolRuntimeError>

Prepares baseline tools for the configured backends before building the agent.

The prepared registry is available afterwards from TerminalAgentBuilder::shell_sessions, so an application that rebuilds its agent can adopt it with Self::prepared_shell_sessions instead of preparing again.

§Errors

Fails if provisioning, integrity validation or sandbox protection fails.

Source

pub async fn prepared_shell_sessions( self, sessions: ShellSessionRegistry, ) -> Result<TerminalAgentBuilder<LLM, P, E, H, Prepared>, ToolRuntimeError>

Adopts a registry another builder already prepared with Self::initialize_tools, taking its shell backends with it.

Only this terminal’s own checks run: its working directory and writable paths must not expose the managed tools. Downloads, integrity hashing, version probes and SSH bootstrap — including its connection consent prompt — are not repeated.

§Errors

Rejects a registry that is not prepared, one whose home backend, container or SSH server set changed after preparation, and writable grants that expose the managed tools.

Source§

impl<LLM, P, E, H> TerminalAgentBuilder<LLM, P, E, H, Prepared>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static, H: Hook,

Source

pub const fn shell_sessions(&self) -> &ShellSessionRegistry

The prepared registry, for a later builder to adopt with TerminalAgentBuilder::prepared_shell_sessions.

Trait Implementations§

Source§

impl<LLM, P, E, H, S> Debug for TerminalAgentBuilder<LLM, P, E, H, S>
where LLM: LanguageModel + Clone, P: PermissionHandler + 'static, E: Executor + Clone + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<LLM, P, E, H = (), S = Unprepared> !RefUnwindSafe for TerminalAgentBuilder<LLM, P, E, H, S>

§

impl<LLM, P, E, H = (), S = Unprepared> !Unpin for TerminalAgentBuilder<LLM, P, E, H, S>

§

impl<LLM, P, E, H = (), S = Unprepared> !UnsafeUnpin for TerminalAgentBuilder<LLM, P, E, H, S>

§

impl<LLM, P, E, H = (), S = Unprepared> !UnwindSafe for TerminalAgentBuilder<LLM, P, E, H, S>

§

impl<LLM, P, E, H, S> Freeze for TerminalAgentBuilder<LLM, P, E, H, S>
where AgentBuilder<LLM, LLM, LLM, H>: Freeze, TerminalTool<P, E>: Freeze, PhantomData<S>: Freeze,

§

impl<LLM, P, E, H, S> Send for TerminalAgentBuilder<LLM, P, E, H, S>
where AgentBuilder<LLM, LLM, LLM, H>: Send, TerminalTool<P, E>: Send, PhantomData<S>: Send,

§

impl<LLM, P, E, H, S> Sync for TerminalAgentBuilder<LLM, P, E, H, S>
where AgentBuilder<LLM, LLM, LLM, H>: Sync, TerminalTool<P, E>: Sync, PhantomData<S>: Sync,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more