- 
                Notifications
    You must be signed in to change notification settings 
- Fork 36
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
          
     Open
      
      
            sordonia
  wants to merge
  17
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
as/agent_as_tool
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Agent as tool #169
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            17 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      99e68a8
              
                agent as tool
              
              
                 9e40c85
              
                retry_on_exception
              
              
                 31596ab
              
                black
              
              
                 8758e7c
              
                black
              
              
                 603eb95
              
                Update debug_gym/gym/tools/agent.py
              
              
                sordonia b97d84c
              
                Update debug_gym/gym/tools/agent.py
              
              
                sordonia 2c57948
              
                remove raise ValueError, handled by from_file
              
              
                 ff97ed5
              
                Merge branch 'as/agent_as_tool' of github.com:microsoft/debug-gym int…
              
              
                 3dec0ed
              
                llm_name -> llm_config.name
              
              
                 81734fb
              
                name -> model_name
              
              
                 4196ef7
              
                Merge remote-tracking branch 'origin/main' into as/agent_as_tool
              
              
                 b92d698
              
                remove "none" from if logger
              
              
                 0d0edab
              
                fix name
              
              
                 5d3cde1
              
                Merge remote-tracking branch 'origin/main' into as/agent_as_tool
              
              
                 f90d5b3
              
                Merge branch 'main' into as/agent_as_tool
              
              
                xingdi-eric-yuan 0b59b29
              
                Merge branch 'main' into as/agent_as_tool
              
              
                matheper bfff277
              
                Update debug_gym/gym/tools/agent.py
              
              
                sordonia File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import logging | ||
|  | ||
| 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="") Send a query to this specialized agent.\n""" | ||
| ] | ||
| 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 | ||
| ): | ||
| 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 | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this
history? A reference to an agent'shistory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But do you have an example of how it is use?