Skip to main content

Sending Input

send_input

handle.send_input("Hello!").await?;
Send user message to agent.

send

handle.send(InputMessage::UserInput("Hello!".to_string())).await?;
Send any InputMessage variant.

Permissions

send_permission_response

handle.send_permission_response(
    "Bash",      // tool_name
    true,        // allowed
    false        // remember
).await?;
Respond to permission request.

set_dangerous_skip_permissions

handle.set_dangerous_skip_permissions(true).await?;
Toggle permission bypass at runtime.

is_dangerous_skip_permissions_enabled

let bypassed = handle.is_dangerous_skip_permissions_enabled().await;
Check if permissions are bypassed.

Async Tools

send_tool_result

handle.send_tool_result(
    "tool_use_123",
    ToolResult::success("Done")
).await?;
Send result for async tool.

Output Subscription

subscribe

let mut rx = handle.subscribe();

while let Ok(chunk) = rx.recv().await {
    match chunk {
        OutputChunk::TextDelta(text) => print!("{}", text),
        OutputChunk::Done => break,
        _ => {}
    }
}
Subscribe to output stream. MUST call before send_input.

State Management

state

let state = handle.state().await;
Get current AgentState.

is_idle / is_processing / is_done

if handle.is_idle().await {
    // Agent is idle
}

if handle.is_processing().await {
    // Agent is working
}

if handle.is_done().await {
    // Agent finished
}

session_id

let id = handle.session_id();
Get session ID.

Control

interrupt

handle.interrupt().await?;
Cancel current operation gracefully.

shutdown

handle.shutdown().await?;
Stop agent and clean up.

Metadata

set_custom_metadata

handle.set_custom_metadata(
    "working_folder",
    "/path/to/project"
).await?;
Update session metadata (works on running agent).

get_custom_metadata

let folder = handle.get_custom_metadata("working_folder").await;
Get custom metadata value.

set_conversation_name

handle.set_conversation_name("Debug Python Script").await?;
Set conversation name.

conversation_name

let name = handle.conversation_name().await;
Get conversation name.

Session Rules

add_session_rule

handle.add_session_rule(
    PermissionRule::allow_tool("Write")
).await?;
Add in-memory permission rule.