You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide demonstrates how to build an intelligent code agent that can analyze and manipulate codebases using Codegen's LangChain integration.
8
+
This guide demonstrates how to build an intelligent code agent that can analyze and manipulate codebases.
9
9
10
-
This agent access to powerful code viewing and manipulation tools powered by Codegen, including:
11
-
-`RevealSymbolTool`: reveal all N-th degree dependencies and usages of a function
12
-
-`MoveSymbolTool`: move a symbol between files, updating all imports etc. (guaranteed correctness)
13
-
-`SemanticEditTool`: implementation of Cursor-style smart file editing
14
-
-`SemanticSearchTool`: search over an index of vector embeddings for files
10
+
```python
11
+
from codegen import CodeAgent, Codebase
12
+
13
+
# Grab a repo from Github
14
+
codebase = Codebase.from_repo('fastapi/fastapi')
15
15
16
-
<Info>View the full code for the default tools and agent implementation in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/src/codegen/extensions/langchain)</Info>
16
+
# Create a code agent with read/write codebase access
17
+
agent = CodeAgent(codebase)
18
+
19
+
# Run the agent with a prompt
20
+
agent.run("Tell me about this repo")
21
+
```
17
22
18
-
# Agent Starter Code
23
+
The agent has access to powerful code viewing and manipulation tools powered by Codegen, including:
24
+
-`ViewFileTool`: View contents and metadata of files
25
+
-`SemanticSearchTool`: Search over code using natural language queries
26
+
-`SemanticEditTool`: Make intelligent edits to files
27
+
-`RevealSymbolTool`: Analyze symbol dependencies and usages
28
+
-`MoveSymbolTool`: Move symbols between files with import handling
29
+
- And many more...
19
30
20
-
Below is a code snippet you can run as-is to solve SWE bench issues.
31
+
<Info>View the full code for the default tools and agent implementation in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/src/codegen/extensions/langchain/tools)</Info>
32
+
33
+
# Basic Usage
34
+
35
+
The following example shows how to create and run a `CodeAgent`:
21
36
22
37
```python
23
-
from codegen import Codebase
24
-
from codegen.extensions.langchain.agent import create_agent_with_tools
RevealSymbolTool(codebase), # Analyze symbol relationships
53
-
SemanticEditTool(codebase), # Make semantic edits
54
-
]
55
-
56
-
57
-
agent = create_agent_with_tools(codebase, tools)
58
-
59
-
# Using a prompt from SWE Bench
60
-
issue ="""Enable quiet mode/no-verbose in CLI for use in pre-commit hook There seems to be only an option to increase the level of verbosity when using SQLFluff [CLI](https://docs.sqlfluff.com/en/stable/cli.html), not to limit it further. It would be great to have an option to further limit the amount of prints when running `sqlfluff fix`, especially in combination with deployment using a pre-commit hook. For example, only print the return status and the number of fixes applied, similar to how it is when using `black` in a pre-commit hook:  This hides the potentially long list of fixes that are being applied to the SQL files, which can get quite verbose."""
61
-
prompt =f"""
62
-
Hey CodegenBot!
63
-
64
-
Here's a SWE task for you. Please solve this task diligently.
65
-
66
-
>>>>> ISSUE TEXT <<<<<
67
-
{issue}
68
-
>>>>> ISSUE TEXT <<<<<
69
-
70
-
Godspeed, CodegenBot! 🚀
71
-
"""
72
-
73
-
# Run the agent
74
-
result = agent.invoke(
75
-
{'input': prompt},
76
-
config={"configurable": {"session_id": "demo"}}
77
-
)
40
+
# Grab a repo from Github
41
+
codebase = Codebase.from_repo('fastapi/fastapi')
42
+
43
+
# Create a code agent with read/write codebase access
44
+
agent = CodeAgent(codebase)
45
+
46
+
# Run the agent with a prompt
47
+
agent.run("Tell me about this repo")
78
48
```
49
+
<Note>Your `ANTHROPIC_API_KEY` must be set in your env.</Note>
79
50
80
-
## Step 1: Tool Configuration
51
+
#Available Tools
81
52
82
-
The agent comes with several built-in tools for code operations:
53
+
The agent comes with a comprehensive set of tools for code analysis and manipulation. Here are some key tools:
83
54
84
55
```python
85
56
from codegen.extensions.langchain.tools import (
57
+
ViewFileTool,
58
+
SemanticSearchTool,
59
+
SemanticEditTool,
60
+
RevealSymbolTool,
61
+
MoveSymbolTool,
62
+
EditFileTool,
86
63
CreateFileTool,
87
64
DeleteFileTool,
88
-
EditFileTool,
89
65
ListDirectoryTool,
90
-
MoveSymbolTool,
91
-
RenameFileTool,
92
-
RevealSymbolTool,
93
66
SearchTool,
94
-
SemanticEditTool,
95
-
ViewFileTool,
96
67
)
97
-
98
-
tools = [
99
-
ViewFileTool(codebase), # View file contents
100
-
ListDirectoryTool(codebase), # List directory contents
RevealSymbolTool(codebase), # Analyze symbol relationships
108
-
SemanticEditTool(codebase), # Make semantic edits
109
-
]
110
68
```
111
69
112
-
## Step 2: Setting Up the Agent
70
+
<Note>View the full set of [tools on Github](https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/extensions/langchain/tools.py)</Note>
113
71
114
-
You can create an agent using `create_agent_with_tools`:
72
+
Each tool provides specific capabilities:
115
73
116
-
```python
117
-
from langchain_openai import ChatOpenAI
118
-
from codegen import Codebase
119
-
from codegen.extensions.langchain.agent import create_agent_with_tools
0 commit comments