Skip to content

Commit 5806b6f

Browse files
authored
feat: adds extra tools to codebase agent (#594)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x ] I have added tests for my changes - [ x] I have updated the documentation or added new documentation as needed --------- Co-authored-by: kopekC <[email protected]>
1 parent 818ef15 commit 5806b6f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/codegen/agents/code_agent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from typing import Optional
22
from uuid import uuid4
33

4+
from langchain.tools import BaseTool
5+
46
from codegen.extensions.langchain.agent import create_codebase_agent
57
from codegen.sdk.core.codebase import Codebase
68

79

810
class CodeAgent:
911
"""Agent for interacting with a codebase."""
1012

11-
def __init__(self, codebase: Codebase):
13+
def __init__(self, codebase: Codebase, tools: Optional[list[BaseTool]] = None):
1214
self.codebase = codebase
13-
self.agent = create_codebase_agent(self.codebase)
15+
self.agent = create_codebase_agent(self.codebase, additional_tools=tools)
1416

1517
def run(self, prompt: str, session_id: Optional[str] = None) -> str:
1618
if session_id is None:

src/codegen/extensions/langchain/agent.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Demo implementation of an agent with Codegen tools."""
22

3+
from typing import Optional
4+
35
from langchain.agents import AgentExecutor, create_tool_calling_agent
46
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
57
from langchain.hub import pull
@@ -34,6 +36,7 @@ def create_codebase_agent(
3436
temperature: float = 0,
3537
verbose: bool = True,
3638
chat_history: list[BaseMessage] = [],
39+
additional_tools: Optional[list[BaseTool]] = None,
3740
) -> RunnableWithMessageHistory:
3841
"""Create an agent with all codebase tools.
3942
@@ -42,6 +45,8 @@ def create_codebase_agent(
4245
model_name: Name of the model to use (default: gpt-4)
4346
temperature: Model temperature (default: 0)
4447
verbose: Whether to print agent's thought process (default: True)
48+
chat_history: Optional list of messages to initialize chat history with
49+
additional_tools: Optional list of additional tools to provide to the agent
4550
4651
Returns:
4752
Initialized agent with message history
@@ -78,6 +83,9 @@ def create_codebase_agent(
7883
# GithubCreatePRCommentTool(codebase),
7984
# GithubCreatePRReviewCommentTool(codebase),
8085
]
86+
# Add additional tools if provided
87+
if additional_tools:
88+
tools.extend(additional_tools)
8189

8290
prompt = ChatPromptTemplate.from_messages(
8391
[

src/codegen/sdk/core/codebase.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,10 @@ def get_modified_symbols_in_pr(self, pr_id: int) -> tuple[list[Symbol], str]:
13181318
patch = cg_pr.get_pr_diff()
13191319
return cg_pr.modified_symbols, patch
13201320

1321+
def create_pr_comment(self, pr_number: int, body: str) -> None:
1322+
"""Create a comment on a pull request"""
1323+
return self._op.create_pr_comment(pr_number, body)
1324+
13211325

13221326
# The last 2 lines of code are added to the runner. See codegen-backend/cli/generate/utils.py
13231327
# Type Aliases

0 commit comments

Comments
 (0)