-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_flow.py
More file actions
42 lines (32 loc) · 1.16 KB
/
basic_flow.py
File metadata and controls
42 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from agentflowpy import SimpleAgent, Context, AGENT_START, AGENT_END
# import logging
# logging.basicConfig(
# level=logging.DEBUG,
# format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
# )
# Create agent
agent = SimpleAgent[str]()
# Create context
ctx = Context[str](id="ctx1", messages=["hello"])
# Add context and switch to it
agent.add_context(ctx)
# Define flow steps
def start_step(context: Context[str]):
print("Start step, messages:", context.messages)
context.messages.append("from start_step")
return "second_step" # Return next step tag
def second_step(context: Context[str]):
print("Second step, messages:", context.messages)
context.messages.append("finished")
return AGENT_END # to end the flow or AGENT_START to create a loop
# Register steps
agent.register(start_step, tag=AGENT_START)
agent.register(second_step, tag="second_step")
# Run
agent.run("ctx1")
# After run
print("Final messages in context:", agent.contexts["ctx1"].messages)
# Expected output:
# Start step, messages: ['hello']
# Second step, messages: ['hello', 'from start_step']
# Final messages in context: ['hello', 'from start_step', 'finished']