Flows (Session Management)
In Railtracks, flows are the primary way to organize your agent runs. Think of a Flow as a blueprint that you invoke to start a run. A single Flow can be invoked multiple times to execute the same agentic process. This guide provides concrete examples to help you get started with Flows.
Quickstart
To get started with Flows, you simply need to provide an entry point and a name.
import railtracks as rt
agent = rt.agent_node(
name="MyAgent",
system_message="You are a helpful assistant that can answer questions and perform tasks.",
llm=rt.llm.OpenAILLM("gpt-4o"),
)
# Create your flow by supplying an entry point.
flow = rt.Flow(name="MyFlow", entry_point=agent)
# And then invoke it with some input!
response = flow.invoke("What is the capital of France?")
print(response)
Passing Configuration
If you want to apply configurations scoped to a specific Flow, you can pass them in during the Flow's creation.
# Configuration options are passed as keyword arguments during initialization
flow = rt.Flow(
name="MyFlow",
entry_point=agent,
timeout=60,
end_on_error=True,
payload_callback=lambda payload: print("Payload:", payload)
)
Injecting Context
Sometimes you may want generic context items to be available across all runs of a Flow. In other cases, you might want context scoped to a specific run (or injected at runtime).
# Creating context shared across instances
flow = rt.Flow(
name="MyFlow",
entry_point=agent,
context={"shared_key": "shared_value"}
)
# Injecting context into specific runs using .update_context()
context_injected_flow = flow.update_context({"run_specific_key": "run_specific_value"})
response = context_injected_flow.invoke("What is the value of shared_key and run_specific_key?")
Warning
The context dictionaries used by Flows are passed by value. If a specific run mutates its context dictionary, those changes will not affect the original context or be passed to other runs.