Skip to content

Commit 60c9418

Browse files
committed
feat(core): clean task agent prompt
1 parent 49b9f20 commit 60c9418

4 files changed

Lines changed: 49 additions & 53 deletions

File tree

src/server/core/acontext_core/llm/agent/task.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def pack_previous_messages_section(
4444
LOG.warning(f"Unknown task id: {ti}")
4545
task_descs.append("(no task linked)")
4646
return "\n---\n".join(
47-
[f"{td}\n{m.to_string()}" for td, m in zip(task_descs, messages)]
47+
[
48+
f"{td}\n{m.to_string(truncate_chars=200)}"
49+
for td, m in zip(task_descs, messages)
50+
]
4851
)
4952

5053

@@ -76,7 +79,7 @@ async def task_agent_curd(
7679
session_id: asUUID,
7780
previous_messages: List[MessageBlob],
7881
messages: List[MessageBlob],
79-
max_iterations=1, # task curd agent only receive one turn of actions
82+
max_iterations=3, # task curd agent only receive one turn of actions
8083
) -> Result[None]:
8184
async with DB_CLIENT.get_session_context() as db_session:
8285
r = await TD.fetch_current_tasks(db_session, session_id)

src/server/core/acontext_core/llm/complete/openai_sdk.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ async def openai_complete(
6262
)
6363

6464
# Only support tool calls
65-
# _fc = (
66-
# response.choices[0].message.function_call.model_dump()
67-
# if response.choices[0].message.function_call
68-
# else None
69-
# )
7065
_tu = (
7166
[
7267
convert_openai_tool_to_llm_tool(tool)
@@ -75,8 +70,6 @@ async def openai_complete(
7570
if response.choices[0].message.tool_calls
7671
else None
7772
)
78-
# if not _tu and _fc:
79-
# _tu = [_fc]
8073

8174
llm_response = LLMResponse(
8275
role=response.choices[0].message.role,

src/server/core/acontext_core/llm/prompt/task.py

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,45 @@ def system_prompt(cls) -> str:
1111
return f"""You are a Task Management Agent that analyzes user/agent conversations to manage task statuses.
1212
1313
## Core Responsibilities
14-
1. **New Task Detection**: Identify new tasks, goals, or objectives requiring tracking
15-
2. **Task Assignment**: Match messages to existing tasks based on context and content
16-
3. **Status Management**: Update task statuses based on progress and completion signals
14+
1. **Task Tracking**: Collect planned tasks/steps from converations.
15+
2. **Message Matching**: Match messages to existing tasks based on context and content
16+
3. **Status Updating**: Update task statuses based on progress and completion signals
1717
1818
## Task System
1919
**Structure**:
2020
- Tasks have description, status, and sequential order (`task_order=1, 2, ...`) within sessions.
2121
- Messages link to tasks via their IDs.
2222
2323
**Statuses**:
24-
- `pending`: Created but not started (default)
25-
- `running`: Currently being processed
26-
- `success`: Completed successfully
27-
- `failed`: Encountered errors or abandoned
24+
- `pending`
25+
- `running`
26+
- `success`
27+
- `failed`
2828
29-
## Analysis Guidelines
30-
### Planning Detection
29+
## Planning Detection
3130
- Planning messages often consist of user and agent discussions, clarify what's tasks to do at next.
3231
- Append those messages to planning section.
3332
34-
### Task Creation/Modifcation
35-
- Collect planned tasks from converations.
36-
- Tasks are often confirmed by the agent's response to user's requirements.
37-
- Only collect tasks stated by agents/users, don't invent them
38-
- Readout the existing tasks, make sure you will locate the correct existing task when user/agent talks about them.
33+
## Task Creation/Modifcation
34+
- Tasks are often confirmed by the agent's response to user's requirements, don't invent them.
35+
- keep task granularity align with the steps in planning:
36+
1. Do not create just one large and comprehensive task, nor only the first task in the plan.
37+
2. Try use the top-level tasks in the planning(often 3~10 tasks), don't create excessive subtasks.
38+
- Make sure you will locate the correct existing task and modify then when necessary.
3939
- Ensure the new tasks are MECE(mutually exclusive, collectively exhaustive) to existing tasks.
40-
- No matter the task is actionable/executable or not, you job is to honestly record every possible new tasks.
40+
- No matter the task is executing or not, you job is to collect ALL POSSIBLE tasks mentioned in the planning.
4141
- When user asked for tasks modification and agent confirmed, you need to think:
42-
a. user/agent is inside/referring an existing task
43-
b. user/agent is creating a new task that don't have any similar existing task.
44-
If (a), modify the existing task' description using `update_task` tool.
45-
If (b), create a new task following the New Task Creation guidelines.
46-
Understand the Current Tasks, and if not necessary, don't create a similar task, try to locate the existing task and modify it.
42+
a. user/agent is inside/referring an existing task. If so, modify the existing task' description using `update_task` tool.
43+
b. user/agent is creating a new task that don't have any similar existing task. If so, create a new task following the New Task Creation guidelines.
44+
If not necessary, don't create a similar task, try to modify the existing task.
4745
48-
### Append Messages to Task
46+
## Append Messages to Task
4947
- Match agent responses/actions to existing task descriptions and contexts
5048
- No need to link every message, just those messages that are contributed to the process of certain tasks.
5149
- Make sure the messages are contributed to the process of the task, not just doing random linking.
5250
- Update task statuses or descriptions when confident about relationships
5351
54-
### Update Task Status
52+
## Update Task Status
5553
- `running`: When task work begins or is actively discussed
5654
- `success`: When completion is confirmed or deliverables provided
5755
- `failed`: When explicit errors occur or tasks are abandoned
@@ -60,31 +58,28 @@ def system_prompt(cls) -> str:
6058
6159
## Input Format
6260
- Input will be markdown-formatted text, with the following sections:
63-
- `## Current Tasks`: existing tasks, their orders, descriptions, and statuses
64-
- `## Previous Messages`: the history messages of user/agent, help you understand the full context. [no message id]
61+
- `## Current Existing Tasks`: existing tasks, their orders, descriptions, and statuses
62+
- `## Previous Messages`: the history messages of user/agent, help you understand the full context. [no message id, maybe truncated]
6563
- `## Current Message with IDs`: the current messages that you need to analyze [with message ids]
6664
- Message with ID format: <message id=N> ... </message>, inside the tag is the message content, the id field indicates the message id.
6765
68-
## Report your thinking before calling tools
66+
## Report your Thinking
6967
Use extremely brief wordings to report:
70-
- Any new user requirement or planning ? For each task, is it a task modification or creation situation?
71-
- How existing tasks are related to current conversation? Do the existing tasks need to be updated?
72-
- Messages are contributed to which task?
73-
- Do New/Existing tasks' status need to be updated?
74-
- Briefly describe your actions.
75-
- Conform your will call every necessary tools in one response.
76-
77-
## Action Guidelines
78-
- Be precise, context-aware, and conservative.
79-
- Focus on meaningful task management that organizes conversation objectives effectively.
80-
- Use parallel tool calls, and make sure you call the tools in the correct order.
68+
1. Any new user requirement or planning? What are the tasks/steps?
69+
2. For each task, is it a task modification or creation situation?
70+
3. How existing tasks are related to current conversation? Do the existing tasks need to be updated?
71+
4. Messages are contributed to which task?
72+
5. Do New/Existing tasks' status need to be updated?
73+
6. Describe your actions.
74+
7. Confirm your will call every necessary tools in this response.
75+
8. Confirm your will call `finish` tool once every tools are called
8176
"""
8277

8378
@classmethod
8479
def pack_task_input(
8580
cls, previous_messages: str, current_message_with_ids: str, current_tasks: str
8681
) -> str:
87-
return f"""## Current Tasks:
82+
return f"""## Current Existing Tasks:
8883
{current_tasks}
8984
9085
## Previous Messages:
@@ -108,12 +103,12 @@ def tool_schema(cls) -> list[ToolSchema]:
108103
"append_messages_to_planning_section"
109104
].schema
110105
append_messages_to_task_tool = TASK_TOOLS["append_messages_to_task"].schema
111-
# finish_tool = TASK_TOOLS["finish"].schema
106+
finish_tool = TASK_TOOLS["finish"].schema
112107

113108
return [
114109
insert_task_tool,
115110
update_task_tool,
116111
append_messages_to_planning_tool,
117112
append_messages_to_task_tool,
118-
# finish_tool,
113+
finish_tool,
119114
]

src/server/core/acontext_core/schema/session/message.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ def pack_part_line(role: str, part: Part) -> str:
1717
role = REPLACE_NAME.get(role, role)
1818
if part.type not in STRING_TYPES:
1919
return f"<{role}> [{part.type} file: {part.filename}]"
20-
if part.type == "text":
20+
elif part.type == "text":
2121
return f"<{role}> {part.text}"
22-
if part.type == "tool-call":
22+
elif part.type == "tool-call":
2323
tool_call_meta = ToolCallMeta(**part.meta)
2424
return f"<{role}> USE TOOL {tool_call_meta.tool_name}, WITH PARAMS {tool_call_meta.arguments}"
25+
else:
26+
raise TypeError(f"Unknown message part type: {part.type}")
2527

2628

2729
class MessageBlob(BaseModel):
@@ -30,6 +32,9 @@ class MessageBlob(BaseModel):
3032
parts: List[Part]
3133
task_id: Optional[asUUID] = None
3234

33-
def to_string(self) -> str:
34-
lines = [pack_part_line(self.role, p) for p in self.parts]
35-
return "\n".join(lines)
35+
def to_string(self, truncate_chars: int = None, **kwargs) -> str:
36+
lines = [pack_part_line(self.role, p, **kwargs) for p in self.parts]
37+
r = "\n".join(lines)
38+
if truncate_chars is None or len(r) < truncate_chars:
39+
return r
40+
return r[:truncate_chars] + "[...truncated]"

0 commit comments

Comments
 (0)