Skip to content

Commit 80118f1

Browse files
committed
Add AI sidekick command
This commit introduces a new feature where an AI sidekick can assist with tasks. The AI sidekick is initialized with a set of tools for file management and human input. The sidekick can be invoked via the new `sidekick` command in the CLI. Additionally, the `review` command has been updated to clarify that it can review either unstaged changes or a specified commit. The help text for the `--commit` option has been updated to reflect this. Minor changes have also been made to the `get_llm_model` function to allow for a default token size.
1 parent 3e45ebf commit 80118f1

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

aicodebot/agents.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
""" LangChain Agent Setup """
2+
from langchain.agents import AgentType, initialize_agent, load_tools
3+
from langchain.agents.agent_toolkits import FileManagementToolkit
4+
5+
SIDEKICK_PROMPT_PREFIX = """
6+
You are a programming assistant named AICodeBot, acting as a sidekick to a human developer.
7+
You are running in the local repository, so you can interact with the files in the repository
8+
to get more information about the code. If you aren't sure what to do, you can ask the human.
9+
10+
If asking the human for more clarification would produce better results, you can ask the human for more information.
11+
12+
Before changing any local files, you should ALWAYS check with the human developer first, explaining what you are doing,
13+
you can give human multiple choices.
14+
"""
15+
16+
17+
def get_agent(name, llm, verbose):
18+
"""Get the agent by name"""
19+
if name == "sidekick":
20+
# Set up the tools. Basic local file management first
21+
tools = FileManagementToolkit(selected_tools=["read_file", "write_file", "list_directory"]).get_tools()
22+
tools += load_tools(["human"]) # Human input
23+
24+
# Set up the agent
25+
return initialize_agent(
26+
tools,
27+
llm,
28+
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
29+
verbose=verbose,
30+
return_intermediate_steps=True,
31+
agent_kwargs={"prefix": SIDEKICK_PROMPT_PREFIX, "verbose": verbose},
32+
)
33+
else:
34+
raise ValueError(f"Agent {name} not found")

aicodebot/cli.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from aicodebot import version as aicodebot_version
2+
from aicodebot.agents import get_agent
23
from aicodebot.helpers import exec_and_get_output, get_token_length, git_diff_context
34
from dotenv import load_dotenv
45
from langchain.chains import LLMChain
@@ -200,7 +201,7 @@ def fun_fact(verbose):
200201

201202

202203
@cli.command
203-
@click.option("-c", "--commit", help="The commit hash to review.")
204+
@click.option("-c", "--commit", help="The commit hash to review (otherwise look at [un]staged changes).")
204205
@click.option("-v", "--verbose", count=True)
205206
def review(commit, verbose):
206207
"""Do a code review, with [un]staged changes, or a specified commit."""
@@ -232,6 +233,22 @@ def review(commit, verbose):
232233
console.print(response, style=bot_style)
233234

234235

236+
@cli.command
237+
@click.option("--task", "-t", help="The task you want to perform - a description of what you want to do.")
238+
@click.option("-v", "--verbose", count=True)
239+
def sidekick(task, verbose):
240+
"""Get help with a task from your AI sidekick."""
241+
setup_environment()
242+
243+
model = get_llm_model()
244+
llm = ChatOpenAI(model=model, temperature=DEFAULT_TEMPERATURE, max_tokens=3500, verbose=verbose)
245+
246+
agent = get_agent("sidekick", llm, True)
247+
248+
response = agent({"input": task})
249+
console.print(response, style=bot_style)
250+
251+
235252
# ---------------------------------------------------------------------------- #
236253
# Helper functions #
237254
# ---------------------------------------------------------------------------- #
@@ -295,7 +312,7 @@ def setup_environment():
295312
)
296313

297314

298-
def get_llm_model(token_size):
315+
def get_llm_model(token_size=0):
299316
# https://platform.openai.com/docs/models/gpt-3-5
300317
# We want to use GPT-4, if it is available for this OPENAI_API_KEY, otherwise GPT-3.5
301318
# We also want to use the largest model that supports the token size we need

0 commit comments

Comments
 (0)