From 5a77c310bb4f73b347c749b568288fa5d55e38b8 Mon Sep 17 00:00:00 2001 From: codegen-bot Date: Wed, 12 Mar 2025 23:10:22 +0000 Subject: [PATCH 1/2] Create and assign Linear ticket before solving an issue --- src/codegen/extensions/langchain/agent.py | 132 ++++++++++---------- src/codegen/extensions/langchain/prompts.py | 3 +- 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/codegen/extensions/langchain/agent.py b/src/codegen/extensions/langchain/agent.py index c1c796b9a..0c095e074 100644 --- a/src/codegen/extensions/langchain/agent.py +++ b/src/codegen/extensions/langchain/agent.py @@ -12,6 +12,12 @@ from codegen.extensions.langchain.tools import ( CreateFileTool, DeleteFileTool, + LinearCommentOnIssueTool, + LinearCreateIssueTool, + LinearGetIssueCommentsTool, + LinearGetIssueTool, + LinearGetTeamsTool, + LinearSearchIssuesTool, ListDirectoryTool, MoveSymbolTool, ReflectionTool, @@ -20,7 +26,6 @@ ReplacementEditTool, RevealSymbolTool, SearchTool, - # SemanticEditTool, ViewFileTool, ) @@ -46,43 +51,53 @@ def create_codebase_agent( codebase: The codebase to operate on model_provider: The model provider to use ("anthropic" or "openai") model_name: Name of the model to use - verbose: Whether to print agent's thought process (default: True) - chat_history: Optional list of messages to initialize chat history with - **kwargs: Additional LLM configuration options. Supported options: - - temperature: Temperature parameter (0-1) - - top_p: Top-p sampling parameter (0-1) - - top_k: Top-k sampling parameter (>= 1) - - max_tokens: Maximum number of tokens to generate + system_message: Custom system message to use + memory: Whether to enable memory/checkpointing + debug: Whether to enable debug mode + additional_tools: Optional additional tools to include + **kwargs: Additional LLM configuration options Returns: - Initialized agent with message history + Compiled langgraph agent """ llm = LLM(model_provider=model_provider, model_name=model_name, max_tokens=8192, **kwargs) - # Get all codebase tools + # Initialize Linear client if environment variables are set + linear_client = None + linear_tools = [] + try: + from codegen.extensions.linear.linear_client import LinearClient + linear_client = LinearClient() + # Add Linear tools + linear_tools = [ + LinearCreateIssueTool(linear_client), + LinearGetIssueTool(linear_client), + LinearSearchIssuesTool(linear_client), + LinearCommentOnIssueTool(linear_client), + LinearGetIssueCommentsTool(linear_client), + LinearGetTeamsTool(linear_client), + ] + except (ImportError, ValueError): + # Linear client not available or not configured + pass + + # Core codebase tools tools = [ ViewFileTool(codebase), ListDirectoryTool(codebase), SearchTool(codebase), - # EditFileTool(codebase), CreateFileTool(codebase), DeleteFileTool(codebase), RenameFileTool(codebase), - # MoveSymbolTool(codebase), - # RevealSymbolTool(codebase), - # SemanticEditTool(codebase), ReplacementEditTool(codebase), RelaceEditTool(codebase), ReflectionTool(codebase), - # SemanticSearchTool(codebase), - # =====[ Github Integration ]===== - # Enable Github integration - # GithubCreatePRTool(codebase), - # GithubViewPRTool(codebase), - # GithubCreatePRCommentTool(codebase), - # GithubCreatePRReviewCommentTool(codebase), ] + # Add Linear tools if available + if linear_tools: + tools.extend(linear_tools) + # Add additional tools if provided if additional_tools: tools.extend(additional_tools) @@ -102,25 +117,43 @@ def create_chat_agent( additional_tools: Optional[list[BaseTool]] = None, **kwargs, ) -> CompiledGraph: - """Create an agent with all codebase tools. + """Create an agent with chat-focused tools. Args: codebase: The codebase to operate on model_provider: The model provider to use ("anthropic" or "openai") model_name: Name of the model to use - verbose: Whether to print agent's thought process (default: True) - chat_history: Optional list of messages to initialize chat history with - **kwargs: Additional LLM configuration options. Supported options: - - temperature: Temperature parameter (0-1) - - top_p: Top-p sampling parameter (0-1) - - top_k: Top-k sampling parameter (>= 1) - - max_tokens: Maximum number of tokens to generate + system_message: Custom system message to use + memory: Whether to enable memory/checkpointing + debug: Whether to enable debug mode + additional_tools: Optional additional tools to include + **kwargs: Additional LLM configuration options Returns: - Initialized agent with message history + Compiled langgraph agent """ llm = LLM(model_provider=model_provider, model_name=model_name, **kwargs) + # Initialize Linear client if environment variables are set + linear_client = None + linear_tools = [] + try: + from codegen.extensions.linear.linear_client import LinearClient + linear_client = LinearClient() + # Add Linear tools + linear_tools = [ + LinearCreateIssueTool(linear_client), + LinearGetIssueTool(linear_client), + LinearSearchIssuesTool(linear_client), + LinearCommentOnIssueTool(linear_client), + LinearGetIssueCommentsTool(linear_client), + LinearGetTeamsTool(linear_client), + ] + except (ImportError, ValueError): + # Linear client not available or not configured + pass + + # Core codebase tools tools = [ ViewFileTool(codebase), ListDirectoryTool(codebase), @@ -133,6 +166,11 @@ def create_chat_agent( RelaceEditTool(codebase), ] + # Add Linear tools if available + if linear_tools: + tools.extend(linear_tools) + + # Add additional tools if provided if additional_tools: tools.extend(additional_tools) @@ -150,22 +188,8 @@ def create_codebase_inspector_agent( debug: bool = True, **kwargs, ) -> CompiledGraph: - """Create an inspector agent with read-only codebase tools. - - Args: - codebase: The codebase to operate on - model_provider: The model provider to use ("anthropic" or "openai") - model_name: Name of the model to use - system_message: Custom system message to use (defaults to standard reasoner message) - memory: Whether to enable memory/checkpointing - **kwargs: Additional LLM configuration options - - Returns: - Compiled langgraph agent - """ llm = LLM(model_provider=model_provider, model_name=model_name, **kwargs) - # Get read-only codebase tools tools = [ ViewFileTool(codebase), ListDirectoryTool(codebase), @@ -187,26 +211,8 @@ def create_agent_with_tools( debug: bool = True, **kwargs, ) -> CompiledGraph: - """Create an agent with a specific set of tools. - - Args: - codebase: The codebase to operate on - tools: List of tools to provide to the agent - model_provider: The model provider to use ("anthropic" or "openai") - model_name: Name of the model to use - system_message: Custom system message to use (defaults to standard reasoner message) - memory: Whether to enable memory/checkpointing - **kwargs: Additional LLM configuration options. Supported options: - - temperature: Temperature parameter (0-1) - - top_p: Top-p sampling parameter (0-1) - - top_k: Top-k sampling parameter (>= 1) - - max_tokens: Maximum number of tokens to generate - - Returns: - Compiled langgraph agent - """ llm = LLM(model_provider=model_provider, model_name=model_name, **kwargs) memory = MemorySaver() if memory else None - return create_react_agent(model=llm, tools=tools, system_message=system_message, checkpointer=memory, debug=debug) + return create_react_agent(model=llm, tools=tools, system_message=system_message, checkpointer=memory, debug=debug) \ No newline at end of file diff --git a/src/codegen/extensions/langchain/prompts.py b/src/codegen/extensions/langchain/prompts.py index a33157bcd..1a476daab 100644 --- a/src/codegen/extensions/langchain/prompts.py +++ b/src/codegen/extensions/langchain/prompts.py @@ -34,6 +34,7 @@ - Use semantic edits for complex changes - Commit changes after significant modifications - Maintain code quality and consistency + - When asked to solve an issue, first create a Linear ticket to track the work and assign it to yourself before proceeding with the solution Remember: You can combine these tools to perform complex refactoring and development tasks. Always explain your approach before making changes. @@ -42,4 +43,4 @@ the impact of the changes. Only then make the changes. Ensure if specifiying line numbers, it's chosen with room (around 20 lines before and 20 lines after the edit range) -""" +""" \ No newline at end of file From 19368e9f3c9743eae843f4e3493e2d6f29000e8f Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:11:13 +0000 Subject: [PATCH 2/2] Automated pre-commit update --- src/codegen/extensions/langchain/agent.py | 4 +++- src/codegen/extensions/langchain/prompts.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/codegen/extensions/langchain/agent.py b/src/codegen/extensions/langchain/agent.py index 0c095e074..51cc10ae1 100644 --- a/src/codegen/extensions/langchain/agent.py +++ b/src/codegen/extensions/langchain/agent.py @@ -67,6 +67,7 @@ def create_codebase_agent( linear_tools = [] try: from codegen.extensions.linear.linear_client import LinearClient + linear_client = LinearClient() # Add Linear tools linear_tools = [ @@ -139,6 +140,7 @@ def create_chat_agent( linear_tools = [] try: from codegen.extensions.linear.linear_client import LinearClient + linear_client = LinearClient() # Add Linear tools linear_tools = [ @@ -215,4 +217,4 @@ def create_agent_with_tools( memory = MemorySaver() if memory else None - return create_react_agent(model=llm, tools=tools, system_message=system_message, checkpointer=memory, debug=debug) \ No newline at end of file + return create_react_agent(model=llm, tools=tools, system_message=system_message, checkpointer=memory, debug=debug) diff --git a/src/codegen/extensions/langchain/prompts.py b/src/codegen/extensions/langchain/prompts.py index 1a476daab..32ea6258d 100644 --- a/src/codegen/extensions/langchain/prompts.py +++ b/src/codegen/extensions/langchain/prompts.py @@ -43,4 +43,4 @@ the impact of the changes. Only then make the changes. Ensure if specifiying line numbers, it's chosen with room (around 20 lines before and 20 lines after the edit range) -""" \ No newline at end of file +"""