Repository navigation
llm: functional tool calling scheme - #9956
Conversation
94a8730 to
ede207c
Compare
|
@vito I like the |
|
@vito one thing I don't understand in this scheme: if I inject a variable "foo" of type Container in the environment, how is that variable exposed to the llm? As a function? |
|
@shykes Sweet!
Funny you say that, because I tried Gemini without the system prompt and that's immediately what it did. 😂 Agree, will give that a shot! One risk to consider is that this same value is also what gets passed to function arguments. For example:
Technically, your idea should work here too:
But the question is whether the LLM will figure that out. Something tells me the reinforcement of "Directory#1" might help when it's juggling a lot of numbers. But my instincts here could be totally wrong. I'll try!
Currently, it gets expanded in the prompt like a regular prompt variable - so the pattern is to explicitly reference it: dagger/modules/botsbuildingbots/evals/main.go Lines 44 to 56 in ede207c The LLM never actually learns their names at the moment - it just jumps right into action with the To be clear, this tool calling scheme has no concept of variables, or named values, based on the theory that we don't need it to, which needs more testing but seems plausible to me so far. I think if this can work, it's better (more efficient, simpler mechanics). Essentially, setting a variable for an LLM does two things:
If we ever need to, we can maybe preserve a hint in the expanded value, like |
|
re: In either case at least one model is probably going to mess up. |
4fcbbeb to
6675d38
Compare
one of my tests actually benefits from _undo, so let's just keep them all enabled, as this was more out of an abundance of caution Signed-off-by: Alex Suraci <[email protected]>
usage:
dagger run go test
Signed-off-by: Alex Suraci <[email protected]>
* do a bit of world-building * clarify immutability/state interaction * nudge it towards using tools to explore before giving up * suggest setting a variable at the end * make system prompt consistent across all models * always apply system prompt (previously OpenAI was excepted) * allow being overridden (previously Gemini didn't) Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
* don't need _objects if we just add a tool for each var * listing tools ahead of time helps Gemini realize it needs to select tools Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
saw some guessing, don't want none of that Signed-off-by: Alex Suraci <[email protected]>
This reverts commit 63f4266. Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
kind of silly implementation, but gets the job done Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
model behavior seems to vary wildly at the moment - it's pretty hesitant to follow instructions, but that seems like a problem independent from the goal of this test Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Explanation in comment. Without this tool gpt-4o reliably refuses to operate on the current state. The problem goes away by the mere presence of this tool, without even calling it. Signed-off-by: Alex Suraci <[email protected]>
so that it knows it can swap back to it, even if it was never told its ID currentState ALMOST helps with this, but not really, since it doesn't go into message history Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
For when you can't/don't want to reference them directly in your prompt. Tested with GPT-4o and Claude 3.7 sonnet, but Gemini has trouble. Signed-off-by: Alex Suraci <[email protected]>
| // strip $foo var prefix | ||
| key = strings.TrimPrefix(key, "$") |
There was a problem hiding this comment.
Mostly a remnant of when it was all variable-oriented, since some models (or even the same model) would opt to include the $ prefix when referencing variables. The general idea is to be liberal in what we accept, considering how moody a lot of models can be, and a lot of them aren't capable of strictly adhering to a format. (Even Gemini has very very limited support for it - only date-time and one other type I can't remember, no regexes)
|
Last few commits made some incremental improvements to the tool scheme:
|
seems like more models need this than don't Signed-off-by: Alex Suraci <[email protected]>
dont want the model to think these are the ONLY possible inputs Signed-off-by: Alex Suraci <[email protected]>
this is supported, and some models try it Signed-off-by: Alex Suraci <[email protected]>
New evals system
(EDIT: this is still really experimental, moved to https://github.com/vito/daggerverse/tree/main/botsbuildingbots)
evalsso we can quickly get a sense of how well each model understands our tool calling scheme as we iterate on it.evalsgo.READMEfor the tool calling scheme.New tool calling scheme
Based on these evaluations I've ended up with a pretty svelte tool calling scheme:
select<Type>(id: "<Type>#123"):selectContainer(id: "Container#1"){"selected":"Container#123"}<Type>_<function>(...)Container_withExec(args: ["foo", "bar"])Container_withMountedDirectory(source: "Directory#1"){"selected":"Container#123"}for Object responses{"result":42}for Scalar or Array-of-Scalar responses{"objects":["Container#123", "Container#124]}for Array-of-Object responsesThose two are foundational, and get us really far on their own, but the following tools were added after to support more cases and situations:
currentSelectionYour current selection: Container#1returntool someday.readVariable(name: "foo")This new scheme is strongly influenced by the idea that our LLM API should work just like functions. You set variables as a jumping off point, let the model traverse the DAG, and inspect the resulting state.
Sequence IDs vs. hashes
The key idea that unlocked this scheme was a new LLM-optimized format for referring to objects.
Container@xxh3:abcdef1234567890becomes simplyContainer#1. We just keep track of what IDs we've seen within the session, with per-type sequence numbers.With this primitive, we don't need
_undoor one-tool-per-variable. We just need a tool for changing the current selection to an ID, and to have the response from each tool (including functions) clearly indicate the ID of any new selection.In my testing and research LLMs can easily handle this scheme, compared to hashes which are (theoretically) more difficult for them to juggle, and variables which come with a high cost (see below).
Sequence IDs vs. variables
An earlier iteration exposed variables as individual tools, to assist with models like Gemini that needed strong hints as to what objects were available to them and what tools they had.
select_foo: Set the current context to $foo (Container@xxh3:abcdef1234567890). Available tools: ...That same iteration also exposed
_saveAsso the model can 1) make checkpoint variables and 2) return values to the user.This scheme combined had poor scaling characteristics:
Switching to
select<Type>addresses all of these concerns:Bug fixes & expanded capabilities
tool_use/tool_responseor something)8k80k charactersFile.contentsagainst the binary it built