-
Notifications
You must be signed in to change notification settings - Fork 37
Agent as tool #169
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
base: main
Are you sure you want to change the base?
Agent as tool #169
Changes from 2 commits
99e68a8
9e40c85
31596ab
8758e7c
603eb95
b97d84c
2c57948
ff97ed5
3dec0ed
81734fb
4196ef7
b92d698
0d0edab
5d3cde1
f90d5b3
0b59b29
bfff277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import logging | ||
| import os | ||
| from os.path import join as pjoin | ||
sordonia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from debug_gym.agents.history_tracker import build_history_prompt | ||
| from debug_gym.gym.entities import Observation | ||
| from debug_gym.gym.tools.tool import EnvironmentTool | ||
| from debug_gym.gym.tools.toolbox import Toolbox | ||
| from debug_gym.gym.utils import is_subdirectory, show_line_number | ||
| from debug_gym.llms.base import LLM | ||
|
|
||
|
|
||
| @Toolbox.register() | ||
| class AgentTool(EnvironmentTool): | ||
| name: str = "agent" | ||
| examples = [ | ||
| """agent(query="") Executes query to send to this specialized agent.\n""" | ||
sordonia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
| description = ( | ||
| "This tool allows to call a large language model specialized agent, and therefore to query for information and exploit capabilities in the model.\n" | ||
| + "\n".join(examples) | ||
| ) | ||
| arguments = { | ||
| "query": { | ||
| "type": ["string"], | ||
| "description": "The request to the agent.", | ||
| }, | ||
| } | ||
|
|
||
| def __init__( | ||
| self, history, llm_name=None, llm_config=None, llm_config_file_path=None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the HistoryTracker of the caller agent, the agentic tool might want to peek at the interactions of the caller agent
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But do you have an example of how it is use? |
||
| ): | ||
| self._history = history | ||
| self.logger = logging.getLogger("agent_logger") | ||
| self._llm = LLM.instantiate( | ||
| llm_name=llm_name, | ||
| llm_config=llm_config, | ||
| llm_config_file_path=llm_config_file_path, | ||
| logger=self.logger, | ||
| ) | ||
| self.llm_config = self._llm.config | ||
| super().__init__() | ||
|
|
||
| def use( | ||
| self, | ||
| environment, | ||
| query: str, | ||
| ) -> Observation: | ||
| messages = build_history_prompt( | ||
| self._history.filter_out(actions=[None]), | ||
| self._llm, | ||
| False, | ||
| ) | ||
| messages.append( | ||
| { | ||
| "role": "user", | ||
| "content": query, | ||
| } | ||
| ) | ||
| llm_response = self._llm.generate(messages, [], tool_choice="none") | ||
|
|
||
| return Observation( | ||
| self.name, | ||
| llm_response.response, | ||
| ) | ||
|
|
||
| def __copy__(self): | ||
| cls = self.__class__ | ||
| result = cls.__new__(cls) | ||
| result.__dict__.update(self.__dict__) | ||
| return result | ||
|
|
||
| def __deepcopy__(self, memo): | ||
| cls = self.__class__ | ||
| result = cls.__new__(cls) | ||
|
|
||
| result.logger = logging.getLogger("agent_logger") | ||
| result._llm = LLM.instantiate( | ||
| llm_config=result.llm_config, | ||
| logger=result.logger, | ||
| ) | ||
| result._history = self._history.copy() | ||
| return result | ||
Uh oh!
There was an error while loading. Please reload this page.