Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tool.call should accept mutable &self #196

Open
1 task done
klntsky opened this issue Jan 13, 2025 · 0 comments
Open
1 task done

feat: Tool.call should accept mutable &self #196

klntsky opened this issue Jan 13, 2025 · 0 comments

Comments

@klntsky
Copy link

klntsky commented Jan 13, 2025

  • I have looked for existing issues (including closed) about this

Feature Request

Motivation

I want to persist some state in the tool.

Proposal

Change:

    /// The tool execution method.
    /// Both the arguments and return value are a String since these values are meant to
    /// be the output and input of LLM models (respectively)
    fn call(
        &self,
        args: Self::Args,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + Sync;

to

    /// The tool execution method.
    /// Both the arguments and return value are a String since these values are meant to
    /// be the output and input of LLM models (respectively)
    fn call(
        &mut self,
        args: Self::Args,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + Sync;

Alternatives

Currently, I'm forced to store data behind an Arc, so that I can update it and access later:

#[derive(Deserialize, Serialize)]
pub struct MyTool {
    #[serde(skip)]
    pub state: Arc<Mutex<MyToolRuntime>>,
    #[serde(skip)]
    pub response: Arc<Mutex<Option<MyToolResponse>>>,
}

I'm not sure if there is an easier way right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant