pub struct PerCallTools<'w, 's> { /* private fields */ }Expand description
The tools registered per call, and where a call of an agent’s works:
for a plugin that builds a call somewhere else, as rig-basics’ Preview
builds it on an overlay of the workspace, or wraps a call where it
works, as its Checkpoint does. The plugin inits ProjectRoot, which
this reads: without it the system using this fails. A tool replaced
(its entity Disabled) is not seen.
use std::sync::Arc;
use bevy_ecs::system::RunSystemOnce;
use rig_harness::prelude::*;
use rig_harness::rig_core::effect::EffectKind;
use rig_harness::rig_core::message::{ToolFunction, ToolName};
use rig_harness::rig_core::serve::serve_inline;
use rig_harness::rig_tools::{Write, overlay::Overlay};
let mut app = App::new();
app.add_tool_per_call(Write::default(), ToolOptions::default(), |place| Write {
workspace: place.workspace,
base: Some(place.base),
confine: place.confine,
..Write::default()
});
// It exists; nothing is written to it.
let dir = std::env::current_dir()?;
let agent = app.world_mut().spawn(WorkDir(dir.clone())).id();
let project = app.world().resource::<ProjectWorkspace>().0.clone();
let overlay = Arc::new(Overlay::new(project));
let on = overlay.clone();
let ran = app.world_mut().run_system_once(move |tools: PerCallTools| {
let place = tools.place(Some(agent), on.clone());
let (base, confine) = (place.base.clone(), place.confine);
let quiet = place.live.is_none() && place.spill.is_none();
let missing = tools.build("read", tools.place(None, on.clone()));
(tools.build("write", place), missing, base, confine, quiet)
});
let (write, missing, base, confine, quiet) = ran.map_err(|failure| failure.to_string())?;
assert_eq!(base, dir);
assert!(confine && quiet && missing.is_none());
let CallHandler(handler) = write.ok_or("write is registered per call")?;
let args = serde_json::json!({ "path": "per-call-doc.txt", "content": "one\n" });
let call = ToolCall::from_wire("w1", ToolFunction::new(ToolName::new("write")?, args));
bevy_tasks::block_on(serve_inline(&handler.0, EffectKind::from(&call)))?;
// The write went to the overlay, and not to the disk.
assert_eq!(overlay.changes().len(), 1);
assert!(!dir.join("per-call-doc.txt").exists());Implementations§
Source§impl PerCallTools<'_, '_>
impl PerCallTools<'_, '_>
Sourcepub fn place(
&self,
agent: Option<Entity>,
workspace: Arc<dyn Workspace>,
) -> CallPlace
pub fn place( &self, agent: Option<Entity>, workspace: Arc<dyn Workspace>, ) -> CallPlace
A call of agent‘s working in workspace: its base is the agent’s
WorkDir, which confines it, else the ProjectRoot. It has no
live and no spill, so a call built on an overlay writes nowhere
else; a call that runs for real elsewhere sets spill itself
(Scratch::spill). confine limits the file tools’ paths; it is
no process sandbox.
Trait Implementations§
impl<'w, 's> ReadOnlySystemParam for PerCallTools<'w, 's>where
Query<'w, 's, (&'static ToolDef, &'static PerCall)>: ReadOnlySystemParam,
Query<'w, 's, &'static WorkDir>: ReadOnlySystemParam,
Res<'w, ProjectRoot>: ReadOnlySystemParam,
Source§impl SystemParam for PerCallTools<'_, '_>
impl SystemParam for PerCallTools<'_, '_>
Source§type Item<'w, 's> = PerCallTools<'w, 's>
type Item<'w, 's> = PerCallTools<'w, 's>
The item type returned when constructing this system param.
The value of this associated type should be
Self, instantiated with new lifetimes. Read moreSource§fn init_access(
state: &Self::State,
system_meta: &mut SystemMeta,
system_access: &mut SystemAccess,
world: &mut World,
)
fn init_access( state: &Self::State, system_meta: &mut SystemMeta, system_access: &mut SystemAccess, world: &mut World, )
Source§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
Applies any deferred mutations stored in this
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut Self::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
Queues any deferred mutations to be applied at the next
ApplyDeferred.Source§unsafe fn get_param<'w, 's>(
state: &'s mut Self::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Result<Self::Item<'w, 's>, SystemParamValidationError>
unsafe fn get_param<'w, 's>( state: &'s mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Result<Self::Item<'w, 's>, SystemParamValidationError>
Creates a parameter to be passed into a
SystemParamFunction. Read moreAuto Trait Implementations§
impl<'w, 's> !RefUnwindSafe for PerCallTools<'w, 's>
impl<'w, 's> !UnwindSafe for PerCallTools<'w, 's>
impl<'w, 's> Freeze for PerCallTools<'w, 's>
impl<'w, 's> Send for PerCallTools<'w, 's>
impl<'w, 's> Sync for PerCallTools<'w, 's>
impl<'w, 's> Unpin for PerCallTools<'w, 's>
impl<'w, 's> UnsafeUnpin for PerCallTools<'w, 's>
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
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.