Skip to content

Commit 781e835

Browse files
authored
Merge pull request #585 from reworkd/code
💻 Add code writer tool
2 parents 26362c7 + 5e3b175 commit 781e835

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed

next/src/components/AutonomousAgent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class AutonomousAgent {
284284
if (analysis.action == "image") {
285285
message = `🎨 Generating an image with prompt: "${analysis.arg}"...`;
286286
}
287+
if (analysis.action == "code") {
288+
message = `💻 Writing code...`;
289+
}
287290

288291
this.sendMessage({
289292
type: MESSAGE_TYPE_SYSTEM,

next/src/components/ChatWindow.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ const ChatWindow = ({
105105
onScroll={handleScroll}
106106
id={messageListId}
107107
>
108-
<div className="mx-4 rounded-full border border-red-500 bg-red-900/30 p-2 px-4 text-red-100">
109-
🚨{" "}
110-
<a className="link" href="https://status.openai.com/">
111-
OpenAI
112-
</a>{" "}
113-
is currently experiencing issues. As a result, AgentGPT may not be available. 🚨
114-
</div>
115108
{agent !== null && agentMode === PAUSE_MODE && isAgentPaused && (
116109
<FaPause className="animation-hide absolute left-1/2 top-1/2 text-lg md:text-3xl" />
117110
)}

next/src/services/agent-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
createModel,
44
createTasksPrompt,
55
executeTaskPrompt,
6-
startGoalPrompt
6+
startGoalPrompt,
77
} from "../utils/prompts";
88
import type { ModelSettings } from "../utils/types";
99
import { env } from "../env/client.mjs";
@@ -47,7 +47,7 @@ async function analyzeTaskAgent(modelSettings: ModelSettings, goal: string, task
4747

4848
export type Analysis = {
4949
reasoning: string;
50-
action: "reason" | "search" | "wikipedia" | "image";
50+
action: "reason" | "search" | "wikipedia" | "image" | "code";
5151
arg: string;
5252
};
5353

platform/reworkd_platform/web/api/agent/prompts.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@
4040
input_variables=["goal", "task", "tools_overview"],
4141
)
4242

43+
code_prompt = PromptTemplate(
44+
template="""
45+
You are a world-class software engineer and an expert in all programing languages,
46+
software systems, and architecture.
47+
48+
For reference, your high level goal is
49+
{goal}
50+
51+
Answer in the "{language}" language but write code in English.
52+
Provide no information about who you are and focus on writing code.
53+
Ensure code is bug and error free and explain complex concepts through comments
54+
Respond in well-formatted markdown. Ensure code blocks are used for code sections.
55+
56+
Write code to accomplish the following:
57+
{task}
58+
""",
59+
input_variables=["goal", "language", "task"],
60+
)
61+
4362
execute_task_prompt = PromptTemplate(
4463
template="""Answer in the "{language}" language. Given
4564
the following overall objective `{goal}` and the following sub-task, `{task}`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from langchain import LLMChain
2+
3+
from reworkd_platform.web.api.agent.model_settings import ModelSettings, create_model
4+
from reworkd_platform.web.api.agent.prompts import code_prompt
5+
from reworkd_platform.web.api.agent.tools.tool import Tool
6+
7+
8+
class Code(Tool):
9+
description = (
10+
"Useful for writing, reviewing, and refactoring code. Can also fix bugs, "
11+
"and explain programming concepts."
12+
)
13+
public_description = "Write and review code."
14+
15+
def __init__(self, model_settings: ModelSettings):
16+
super().__init__(model_settings)
17+
18+
async def call(self, goal: str, task: str, input_str: str) -> str:
19+
llm = create_model(self.model_settings)
20+
chain = LLMChain(llm=llm, prompt=code_prompt)
21+
22+
return await chain.arun({"goal": goal, "language": "English", "task": task})

platform/reworkd_platform/web/api/agent/tools/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Type, List
22

3+
from reworkd_platform.web.api.agent.tools.code import Code
34
from reworkd_platform.web.api.agent.tools.conclude import Conclude
45
from reworkd_platform.web.api.agent.tools.image import Image
56
from reworkd_platform.web.api.agent.tools.reason import Reason
@@ -20,6 +21,7 @@ def get_external_tools() -> List[Type[Tool]]:
2021
# Wikipedia, # Requires an async version
2122
Image,
2223
Search,
24+
Code,
2325
]
2426

2527

platform/reworkd_platform/web/api/agent/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ class CompletionResponse(BaseModel):
8787

8888
@router.post("/execute")
8989
async def execute_tasks(
90-
req_body: AgentRequestBody,
90+
req_body: AgentRequestBody = Body(
91+
example={
92+
"goal": "Perform tasks accurately",
93+
"task": "Write code to make a platformer",
94+
"analysis": {
95+
"reasoning": "I like to write code.",
96+
"action": "code",
97+
"arg": ""
98+
},
99+
}
100+
),
91101
) -> CompletionResponse:
92102
try:
93103
response = await get_agent_service().execute_task_agent(

0 commit comments

Comments
 (0)