pub struct JsAgent { /* private fields */ }Available on crate feature
js only.Expand description
A ReAct / tool-calling agent for JavaScript.
Implementations§
Source§impl JsAgent
impl JsAgent
Sourcepub fn new(
max_iterations: Option<u32>,
context_tokens: Option<usize>,
recover_from_errors: Option<bool>,
) -> JsAgent
pub fn new( max_iterations: Option<u32>, context_tokens: Option<usize>, recover_from_errors: Option<bool>, ) -> JsAgent
new Agent(maxIterations = 10, contextTokens = 8192, recoverFromErrors = false).
Sourcepub fn register_tool(
&mut self,
name: &str,
description: &str,
schema: &str,
f: Function,
) -> Result<(), JsError>
pub fn register_tool( &mut self, name: &str, description: &str, schema: &str, f: Function, ) -> Result<(), JsError>
Register a tool backed by a JavaScript function (input: string) => string.
Sourcepub fn add_system_prompt(&mut self)
pub fn add_system_prompt(&mut self)
Add the standard ReAct system prompt (with the tool list).
Sourcepub fn step(&mut self, reply: &str) -> Result<JsValue, JsError>
pub fn step(&mut self, reply: &str) -> Result<JsValue, JsError>
Process one text reply. Returns {kind, content, tool?, input?} where
kind is "thought", "action", "observation" or "final".
Sourcepub fn step_response(&mut self, body: &str) -> Result<JsValue, JsError>
pub fn step_response(&mut self, body: &str) -> Result<JsValue, JsError>
Process one raw response body from OpenAI, Anthropic or Ollama.
Returns {kind: "tool_calls", results: [{id, name, success, output}]}
or {kind: "final", text}.
Sourcepub fn openai_tools(&self) -> Result<JsValue, JsError>
pub fn openai_tools(&self) -> Result<JsValue, JsError>
The tools array for OpenAI-style APIs.
Sourcepub fn anthropic_tools(&self) -> Result<JsValue, JsError>
pub fn anthropic_tools(&self) -> Result<JsValue, JsError>
The tools array for Anthropic.
Sourcepub fn transcript(&self) -> String
pub fn transcript(&self) -> String
The conversation as one prompt string (text ReAct).
Sourcepub fn chat_messages(&self) -> Result<JsValue, JsError>
pub fn chat_messages(&self) -> Result<JsValue, JsError>
The conversation as [{role, content}] chat messages (text ReAct).
Trait Implementations§
Source§impl FromWasmAbi for JsAgent
impl FromWasmAbi for JsAgent
Source§impl IntoWasmAbi for JsAgent
impl IntoWasmAbi for JsAgent
Source§impl LongRefFromWasmAbi for JsAgent
impl LongRefFromWasmAbi for JsAgent
Source§impl OptionFromWasmAbi for JsAgent
impl OptionFromWasmAbi for JsAgent
Source§impl OptionIntoWasmAbi for JsAgent
impl OptionIntoWasmAbi for JsAgent
Source§impl RefFromWasmAbi for JsAgent
impl RefFromWasmAbi for JsAgent
Source§type Abi = WasmPtr<WasmRefCell<JsAgent>>
type Abi = WasmPtr<WasmRefCell<JsAgent>>
The Wasm ABI type references to
Self are recovered from.Source§impl RefMutFromWasmAbi for JsAgent
impl RefMutFromWasmAbi for JsAgent
impl SupportsConstructor for JsAgent
impl SupportsInstanceProperty for JsAgent
impl SupportsStaticProperty for JsAgent
Source§impl TryFromJsValue for JsAgent
impl TryFromJsValue for JsAgent
Source§impl VectorFromWasmAbi for JsAgent
impl VectorFromWasmAbi for JsAgent
Source§impl VectorIntoWasmAbi for JsAgent
impl VectorIntoWasmAbi for JsAgent
Auto Trait Implementations§
impl !RefUnwindSafe for JsAgent
impl !Send for JsAgent
impl !Sync for JsAgent
impl !UnwindSafe for JsAgent
impl Freeze for JsAgent
impl Unpin for JsAgent
impl UnsafeUnpin for JsAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.