-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpass_args.py
More file actions
24 lines (18 loc) · 790 Bytes
/
pass_args.py
File metadata and controls
24 lines (18 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from agentflowpy import SimpleAgent, Context, StepLead, AGENT_START, AGENT_END
agent = SimpleAgent[str]()
agent.add_context(Context[str](id="ctx1"))
def ask_name(context: Context[str]):
name = input("What is your name? ")
context.messages.append(f"user_name: {name}")
# Use StepLead to pass name to next ("greet") step
return StepLead(step="greet", kwargs={"name": name})
# or use positional args like:
return StepLead(step="greet", args=(name,))
def greet(context: Context[str], name: str):
greeting = f"Hello, {name}!"
context.messages.append(greeting)
return AGENT_END
agent.register(ask_name, tag=AGENT_START) # Starting step
agent.register(greet, tag="greet")
agent.run("ctx1")
print("Conversation messages:", agent.contexts["ctx1"].messages)