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

Trying out Gemini's Tool API #718

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Trying out Gemini's Tool API #718

wants to merge 15 commits into from

Conversation

DonggeLiu
Copy link
Collaborator

@DonggeLiu DonggeLiu commented Nov 18, 2024

Trying out the Tool API on a new agent (Repairer) as a PoC.
This is an alternative to system instructions (#717, which had an unreproducible error) to address the malformatted response issue.
If this works well, I will use Tool in Prototyper too.

Repairer focuses on fixing fuzz target (and build script) when prototyper encounters a build error. It comes with different prompts (and likely examples later).

@DonggeLiu DonggeLiu marked this pull request as draft November 18, 2024 04:46
@DonggeLiu
Copy link
Collaborator Author

/gcbrun exp -n dg -ag

@DonggeLiu
Copy link
Collaborator Author

Hi @mihaimaruseac I am unsure what's the best way to let an agent focus on one tool in our use case. Could you please let me know if I missed (or am wrong about) anything?

Given the goal is to generate a buildable fuzz target, the agent has two main tasks:

  1. Understand the build error of a given fuzz target, then generate a revised one.
  2. Collect information from the build environment (e.g., inspect source code).

Correspondingly, there are two tools (or FunctionCalls):

  1. A compile function to build the fuzz target when LLM generates a new one, and show build errors (if any).
  2. A Bash function to find or view source code.

I did not separate them into two agents, because I think task 1 needs both tools: In order to understand a build error (e.g., wrong type), the agent needs to cross-check the related source code (e.g., type/function definition).


Also I am unsure if I used the Tool API in the best way.
The API does not support using multiple tools (and passing their function parameter definitions), My mitigation is to define an overall parameter as a struct/object:

function_call:{
overal_parameter: {
  args:{
    tool1_params: {
      args: {...}
    }
    tool2_params: {
      args: {...}
    }
  }
}
}

Then I call tool1/tool2 with the params from tool1_params/tool2_params. I can also define which params are mandatory.

I thought about a flattened struct:

function_call: {
  args:{
    tool1_param_1
    tool1_param_2
    tool2_param_2
    tool2_param_2
  }
}

But LLM can mix/miss some params, and I cannot define which params are mandatory given I don't know which tool will use.

Thanks!

@DonggeLiu
Copy link
Collaborator Author

/gcbrun exp -n dg -ag

@DonggeLiu
Copy link
Collaborator Author

/gcbrun exp -n dg -ag

@DonggeLiu
Copy link
Collaborator Author

@DonggeLiu
Copy link
Collaborator Author

/gcbrun exp -n dg -ag

@DonggeLiu DonggeLiu force-pushed the fuzz-target-repairer branch from 7bcbe5a to 5a775f6 Compare November 19, 2024 09:53
@mihaimaruseac
Copy link
Member

For the agents part I think it all makes sense.

On the Tool API, from the description it looks like it should support multiple functions. Is it that the agents gets confused on which parameters belong to which function? Or the API actually doesn't support multiple functions, although documentation says it does?

@DonggeLiu
Copy link
Collaborator Author

Thanks @mihaimaruseac

Or the API actually doesn't support multiple functions, although documentation says it does?

Yep, it's a limitation from the API, despite the description and definition suggests otherwise.

I recall I discovered this from an exception thrown by vertex when I defined 2 tools.

@mihaimaruseac
Copy link
Member

Yeah, in this case the nested structs work

@oliverchang
Copy link
Collaborator

This is an alternative to system instructions (#717, which had an unreproducible error) to address the malformatted response issue.

System instructions and tools serve different purposes right?

There's still value to having system instructions for describing the general task (I assume this is better than just us prepending this in our first prompt)?

@oliverchang
Copy link
Collaborator

oliverchang commented Nov 22, 2024

@DonggeLiu can you explain the limitations here a bit more?

We can only have 1 tool... but each tool supports multiple functions right? Can't we still achieve what we want with this?

i.e.

tool {
  function_declarations [ bash, compile ]
}

(from https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling)
?

@DonggeLiu
Copy link
Collaborator Author

System instructions and tools serve different purposes right?
There's still value to having system instructions for describing the general task (I assume this is better than just us prepending this in our first prompt)?

Yep, they have different purpose and system instruction can be used to describe general tasks.

When I created #717 and this PR, the main goal was to ensure LLM to respond in a predefined format (XML-style tags) so that we can parse the tool commands (e.g., bash, compile). The instruction content in #717 for this purpose is no longer needed because this PR shows Tool API already ensures all LM responses are in well-formatted JSONs.

I plan to cherry-pick some commits from #717 and this PR so that we use system instructions with a new content, focusing on:

  1. the overall goal
  2. some guidelines when using tools.

@DonggeLiu
Copy link
Collaborator Author

https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling

Thanks, maybe I defined multiple tools instead of multiple functions in one tool and misremembered?
I will re-implement the function declaration as in the doc and verify it here.

On hindsight, I should have committed and pushed the old code with the code and its error is documented in this PR for us to double-check.

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

Successfully merging this pull request may close these issues.

3 participants