Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/multi_agent_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@
def demo():
topic = "milk and cereal"
task = Task(
"Discuss a topic; everyone should speak at least once",
"Discuss a topic",
agents=[jerry, george, elaine, kramer, newman],
context=dict(topic=topic),
instructions="every agent should speak at least once",
)
task.run()

Expand Down
16 changes: 3 additions & 13 deletions src/controlflow/core/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import controlflow
from controlflow.core.agent import Agent
from controlflow.core.controller.moderators import marvin_moderator
from controlflow.core.flow import Flow, get_flow, get_flow_messages
from controlflow.core.flow import Flow, get_flow
from controlflow.core.graph import Graph
from controlflow.core.task import Task
from controlflow.instructions import get_instructions
Expand Down Expand Up @@ -171,12 +171,7 @@ async def _run_agent(
controller=self, agent=agent, tasks=tasks, thread=thread
)

def choose_agent(
self,
agents: list[Agent],
tasks: list[Task],
iterations: int = 0,
) -> Agent:
def choose_agent(self, agents: list[Agent], tasks: list[Task]) -> Agent:
return marvin_moderator(
agents=agents,
tasks=tasks,
Expand Down Expand Up @@ -209,12 +204,7 @@ async def run_once_async(self):
elif len(agents) == 1:
agent = agents[0]
else:
agent = self.choose_agent(
agents=agents,
tasks=tasks,
history=get_flow_messages(),
instructions=get_instructions(),
)
agent = self.choose_agent(agents=agents, tasks=tasks)

await self._run_agent(agent, tasks=tasks)
self._iteration += 1
Expand Down
13 changes: 7 additions & 6 deletions src/controlflow/core/controller/instruction_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class AgentTemplate(Template):

These are your instructions: "{{ agent.instructions or 'No additional instructions provided.'}}"

You must follow these instructions at all times. They define your role and behavior.
You must follow these instructions at all times. They define your role
and behavior.

You are participating in an agentic workflow (a "flow"), parts of which have
been delegated to you and other AI agents. You are being orchestrated by a
"controller" object. DO NOT speak on behalf of other agents or the system.
You can only post messages on behalf of yourself.
You are participating in an agentic workflow (a "flow"), parts of which
have been delegated to you and other AI agents. You are being
orchestrated by a "controller" object.
"""
agent: Agent

Expand Down Expand Up @@ -65,7 +65,8 @@ class TasksTemplate(Template):
objective and criteria for success. Your job is to perform any required
actions and then mark each assigned task as successful. If a task
requires a result, you must provide it. Only work on tasks that are
assigned to you.
assigned to you. Tasks may have multiple agents assigned. Only one agent
can respond or take actions at a time.

### Current tasks

Expand Down
5 changes: 2 additions & 3 deletions src/controlflow/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def __init__(

if additional_instructions := get_instructions():
kwargs["instructions"] = (
kwargs.get("instructions", "")
+ "\n"
+ "\n".join(additional_instructions)
kwargs.get("instructions")
or "" + "\n" + "\n".join(additional_instructions)
).strip()

# setup up relationships
Expand Down