Skip to content

Commit f3cd652

Browse files
committed
Update coordinator understanding about team
1 parent 8d49914 commit f3cd652

2 files changed

Lines changed: 42 additions & 46 deletions

File tree

bindings/ceylon/ceylon/llm/llm_task_coordinator.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,22 @@ class LLMTaskCoordinator(TaskCoordinator):
4040
results: Dict[str, List[TaskResult]] = {}
4141
team_network: nx.Graph = nx.Graph()
4242

43-
def __init__(self, tasks: List[Task], agents: List[LLMTaskOperator], llm=None, tool_llm=None,
44-
name=DEFAULT_WORKSPACE_ID, port=DEFAULT_ADMIN_PORT):
43+
def __init__(self, tasks: List[Task], agents: List[LLMTaskOperator],
44+
context: str,
45+
team_goal: str,
46+
47+
llm=None, tool_llm=None,
48+
name=DEFAULT_WORKSPACE_ID,
49+
port=DEFAULT_ADMIN_PORT):
50+
self.context = context
51+
self.team_goal = team_goal
4552
self.llm = llm
4653
self.tool_llm = tool_llm
4754
self.tasks = tasks
4855
self.agents = agents
4956
self.initialize_team_network()
5057
logger.info(
51-
f"LLM Task Coordinator initialized with {len(tasks)} tasks and {len(self.get_llm_operators)} agents {[agent for agent in self.get_llm_operators]}")
58+
f"LLM Task Coordinator initialized with {len(tasks)} tasks and {len(self.get_llm_operators)} agents {[agent.details().name for agent in self.get_llm_operators]}")
5259
super().__init__(name=name, port=port, tasks=tasks, agents=agents)
5360

5461
def initialize_team_network(self):
@@ -115,23 +122,6 @@ def visualize_team_network(self, output_file: str = None):
115122
async def get_task_executor(self, task: SubTask) -> str:
116123
return await self.get_best_agent_for_subtask(task)
117124

118-
async def update_task(self, idx: int, task: Task):
119-
if len(task.subtasks) == 0:
120-
sub_tasks = await self.generate_tasks_from_description(task)
121-
for sub_task in sub_tasks:
122-
task.add_subtask(sub_task)
123-
124-
# depends_on = [sub_task.name for sub_task in sub_tasks]
125-
# final_sub_task = SubTask(
126-
# name="Generate Final Answer",
127-
# description=f"Based on all previous sub-tasks, provide a comprehensive final answer to the main task: {task.description}",
128-
# required_specialty="Synthesize information and generate conclusive answers",
129-
# depends_on=depends_on,
130-
# )
131-
final_sub_task = await self.generate_final_sub_task_from_description(task)
132-
task.add_subtask(final_sub_task)
133-
return task
134-
135125
@property
136126
def get_llm_operators(self) -> List[LLMTaskOperator]:
137127
operators = []
@@ -186,13 +176,13 @@ def get_valid_agent_name(max_attempts=3):
186176
return get_valid_agent_name()
187177

188178
async def generate_tasks_from_description(self, task: Task) -> List[SubTask]:
189-
190-
# Prompt template
191179
prompt = PromptTemplate.from_template(
192180
"""
193-
Given the following job description, break it down into a main task and 3-5 key subtasks. Each subtask should have a specific description and required specialty.
181+
Given the following job description, context, and team goal, break it down into a main task and 3-5 key subtasks. Each subtask should have a specific description and required specialty.
194182
195183
Job Description: {description}
184+
Context: {context}
185+
Team Goal: {team_goal}
196186
197187
Respond with the tasks and their subtasks in the following format:
198188
@@ -205,55 +195,58 @@ async def generate_tasks_from_description(self, task: Task) -> List[SubTask]:
205195
(Add up to 2 more subtasks if necessary)
206196
207197
Additional Considerations:
198+
- Ensure the subtasks align with the given context and contribute to the team goal
208199
- Prioritize the subtasks in order of importance or chronological sequence
209200
- Ensure each subtask is distinct and contributes uniquely to the main task
210201
- Use clear, action-oriented language for each description
211202
- If applicable, include any interdependencies between subtasks
212203
"""
213204
)
214205

215-
# Chain
216206
structured_llm = self.tool_llm.with_structured_output(SubTaskList)
217207
chain = prompt | structured_llm
218208
sub_task_list = chain.invoke(input={
219-
"description": task.description
209+
"description": task.description,
210+
"context": self.context,
211+
"team_goal": self.team_goal
220212
})
221-
# Make sure subtasks are valid
222213
sub_task_list = self.recheck_and_update_subtasks(subtasks=sub_task_list)
223214
return [t.to_v2(task.id) for t in sub_task_list.sub_task_list]
224215

225216
async def generate_final_sub_task_from_description(self, task: Task) -> SubTask:
226-
227-
# Prompt template
228217
prompt = PromptTemplate.from_template(
229218
"""
230-
Given the following job description and existing subtasks, add a final delivery step to complete the project.
231-
This final step should focus on delivering the completed work.
219+
Given the following job description, existing subtasks, context, and team goal, add a final delivery step to complete the project.
220+
This final step should focus on delivering the completed work and ensuring it aligns with the team goal.
232221
233-
Job Description: {description}
222+
Job Description: {description}
223+
Context: {context}
224+
Team Goal: {team_goal}
234225
235-
Existing Subtasks:
236-
{existing_subtasks}
226+
Existing Subtasks:
227+
{existing_subtasks}
237228
238-
Respond with only the final delivery step in the following format:
229+
Respond with only the final delivery step in the following format:
239230
240-
Final Step:
241-
<Specific description of the final delivery step> - Specialty: <Required specialty or skill> - Depends on: <Names of subtasks that must be completed before this one>
231+
Final Step:
232+
<Specific description of the final delivery step> - Specialty: <Required specialty or skill> - Depends on: <Names of subtasks that must be completed before this one>
242233
243-
Additional Considerations:
244-
- Ensure the final step encompasses presenting or delivering the completed work
245-
- Use clear, action-oriented language for the description
246-
- Include dependencies on relevant existing subtasks
247-
- Focus on delivering the functionality and value of the completed project
248-
"""
234+
Additional Considerations:
235+
- Ensure the final step encompasses presenting or delivering the completed work
236+
- Make sure the final step aligns with the context and contributes to the team goal
237+
- Use clear, action-oriented language for the description
238+
- Include dependencies on relevant existing subtasks
239+
- Focus on delivering the functionality and value of the completed project
240+
"""
249241
)
250242

251-
# Chain
252243
structured_llm = self.tool_llm.with_structured_output(SubTaskModel)
253244
chain = prompt | structured_llm
254245
sub_task: SubTaskModel = chain.invoke(input={
255246
"description": task.description,
256-
"existing_subtasks": "\n".join([f"{t.name}- {t.description}" for t in task.subtasks.values()])
247+
"existing_subtasks": "\n".join([f"{t.name}- {t.description}" for t in task.subtasks.values()]),
248+
"context": self.context,
249+
"team_goal": self.team_goal
257250
})
258251
return sub_task.to_v2(task.id)
259252

bindings/ceylon/tests/tasks/llm_software_agency.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@
5555
]
5656
# enable_log("INFO")
5757
# Initialize TaskManager
58-
task_manager = LLMTaskCoordinator(tasks, agents, tool_llm=tool_llm, llm=llm)
59-
58+
task_manager = LLMTaskCoordinator(tasks, agents, tool_llm=tool_llm, llm=llm,
59+
team_goal="Develop and deliver innovative, secure, and scalable software solutions that drive business value, achieve 95% client satisfaction, and are completed on time and within budget",
60+
context="Utilize agile methodologies to gather and analyze client requirements, architect robust solutions, implement clean and efficient code, conduct thorough testing (including unit, integration, and user acceptance), and deploy using CI/CD practices. Emphasize code quality, performance optimization, and adherence to industry standards throughout the development lifecycle.",
61+
)
62+
# task_manager.visualize_team_network(output_file=None)
6063
# Execute tasks
6164
completed_tasks = asyncio.run(task_manager.async_do(inputs=b""))
6265

0 commit comments

Comments
 (0)