Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime<C: Config> {
    pub model: Model<C::Provider>,
    pub env: Arc<C::Env>,
    pub tools: ToolRegistry,
    /* private fields */
}
Expand description

The crabtalk runtime.

Fields§

§model: Model<C::Provider>§env: Arc<C::Env>§tools: ToolRegistry

Implementations§

Source§

impl<C: Config> Runtime<C>

Source

pub fn add_agent(&self, config: AgentConfig)

Source

pub fn upsert_agent(&self, config: AgentConfig) -> AgentConfig

Source

pub fn remove_agent(&self, name: &str) -> bool

Source

pub fn agent(&self, name: &str) -> Option<AgentConfig>

Source

pub fn agents(&self) -> Vec<AgentConfig>

Source

pub async fn add_ephemeral(&self, config: AgentConfig)

Source

pub async fn remove_ephemeral(&self, name: &str)

Source§

impl<C: Config> Runtime<C>

Source

pub async fn get_or_create_conversation( &self, agent: &str, created_by: &str, ) -> Result<u64>

Get or create a conversation for the given (agent, created_by) identity. Routing order:

  1. If (agent, sender) has an active topic, return that topic’s conversation.
  2. Otherwise return/create the tmp conversation for this pair — in-memory only, no storage I/O, no resume. Topic-bound chats reach storage via switch_topic.
Source

pub async fn load(&self, handle: ConversationHandle) -> Result<u64>

Load a specific conversation by persistent handle.

Source

pub async fn list_active(&self) -> Vec<ActiveConversationInfo>

Source

pub async fn close(&self, id: u64) -> bool

Source

pub async fn steer(&self, conversation_id: u64, content: String) -> Result<()>

Source

pub async fn conversation(&self, id: u64) -> Option<Arc<Mutex<Conversation>>>

Source

pub async fn conversations(&self) -> Vec<Arc<Mutex<Conversation>>>

Source

pub async fn conversation_count(&self) -> usize

Source

pub async fn conversation_id(&self, agent: &str, sender: &str) -> Option<u64>

Source

pub async fn compact(&self, conversation_id: u64) -> Option<String>

Source

pub async fn transfer_to<C2: Config>(&self, dest: &mut Runtime<C2>)

Source§

impl<C: Config> Runtime<C>

Source

pub async fn send_to( &self, conversation_id: u64, content: &str, sender: &str, tool_choice: Option<ToolChoice>, ) -> Result<AgentResponse>

Source

pub fn stream_to( &self, conversation_id: u64, content: &str, sender: &str, tool_choice: Option<ToolChoice>, ) -> impl Stream<Item = AgentEvent> + '_

Source

pub fn guest_stream_to( &self, conversation_id: u64, content: &str, sender: &str, guest: &str, ) -> impl Stream<Item = AgentEvent> + '_

Source§

impl<C: Config> Runtime<C>

Source

pub async fn switch_topic( &self, agent: &str, sender: &str, title: &str, description: Option<&str>, ) -> Result<SwitchOutcome>

Switch the active topic for (agent, sender). Creates a new topic conversation if the title doesn’t exist yet; resumes the existing one otherwise. When creating, writes an EntryKind::Topic memory entry (unless one already exists for the title) so the topic is searchable via search_topics.

Returns the target conversation_id in the outcome. The caller is responsible for telling the user which conversation to route the next message to — this call only updates runtime state.

Source§

impl<C: Config> Runtime<C>

Source

pub fn new( model: Model<C::Provider>, env: Arc<C::Env>, storage: Arc<C::Storage>, memory: SharedMemory, tools: ToolRegistry, ) -> Self

Create a new runtime with the given model, env, storage, memory, and tools.

Source

pub fn storage(&self) -> &Arc<C::Storage>

Access the persistence backend.

Source

pub fn memory(&self) -> &SharedMemory

Access the shared memory store.

Auto Trait Implementations§

§

impl<C> !Freeze for Runtime<C>

§

impl<C> !RefUnwindSafe for Runtime<C>

§

impl<C> Send for Runtime<C>

§

impl<C> Sync for Runtime<C>

§

impl<C> Unpin for Runtime<C>

§

impl<C> UnsafeUnpin for Runtime<C>

§

impl<C> !UnwindSafe for Runtime<C>

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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