Skip to content

Commit

Permalink
Merge pull request #70 from jlowin/printhandler
Browse files Browse the repository at this point in the history
Add live printhandler by default
  • Loading branch information
jlowin authored May 25, 2024
2 parents 4bcc636 + 84d0fde commit e78c87f
Show file tree
Hide file tree
Showing 7 changed files with 400 additions and 296 deletions.
12 changes: 9 additions & 3 deletions src/controlflow/core/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,21 @@ async def _run_agent(self, agent: Agent, tasks: list[Task]):
system_message = SystemMessage(content=instructions)
messages = self.history.load_messages(thread_id=self.flow.thread_id)

# setup handler
if controlflow.settings.enable_tui:
handlers = [TUIHandler()]
elif controlflow.settings.enable_print_handler:
handlers = [PrintHandler()]
else:
handlers = []

# call llm
response_messages = []
async for msg in await completion_async(
messages=[system_message] + messages,
model=agent.model,
tools=tools,
handlers=[TUIHandler()]
if controlflow.settings.enable_tui
else [PrintHandler()],
handlers=handlers,
max_iterations=1,
stream=True,
message_preprocessor=add_agent_name_to_message,
Expand Down
14 changes: 9 additions & 5 deletions src/controlflow/core/controller/instruction_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ class CommunicationTemplate(Template):
On each turn, you must use a tool or post a message. Do not post
messages unless you need to record information in addition to what you
provide as a task's result. This might include your thought process, if
appropriate. You may also post messages if you need to communicate with
other agents to complete a task. You may see other agents post messages;
they may have different instructions than you do, so do not follow their
example automatically.
provide as a task's result, or for the following reasons:
- You need to post a message or otherwise communicate to complete a task.
- You need to communicate with other agents to complete a task.
- You want to write your thought process for future reference.
Note that You may see other agents post messages; they may have
different instructions than you do, so do not follow their example
automatically.
When you use a tool, the tool call and tool result are automatically
posted as messages to the thread, so you never need to write out task
Expand Down
Loading

0 comments on commit e78c87f

Please sign in to comment.