Additional Data and Metadata

How to pass additional data to workflows

When to Use Pass metadata, configuration, or contextual information to specific steps without cluttering the main workflow message flow.

Key Benefits

  • Separation of Concerns: Keep workflow logic separate from metadata
  • Step-Specific Context: Access additional information in custom functions
  • Clean Message Flow: Main message stays focused on content
  • Flexible Configuration: Pass user info, priorities, settings, and more

Access Pattern Use step_input.additional_data for dictionary access to all additional data passed to the workflow.

Example

1from kern.workflow import Step, Workflow, StepInput, StepOutput
2
3def custom_content_planning_function(step_input: StepInput) -> StepOutput:
4 """Custom function that uses additional_data for enhanced context"""
5
6 # Access the main workflow message
7 message = step_input.input
8 previous_content = step_input.previous_step_content
9
10 # Access additional_data that was passed with the workflow
11 additional_data = step_input.additional_data or {}
12 user_email = additional_data.get("user_email", "No email provided")
13 priority = additional_data.get("priority", "normal")
14 client_type = additional_data.get("client_type", "standard")
15
16 # Create enhanced planning prompt with context
17 planning_prompt = f"""
18 STRATEGIC CONTENT PLANNING REQUEST:
19
20 Core Topic: {message}
21 Research Results: {previous_content[:500] if previous_content else "No research results"}
22
23 Additional Context:
24 - Client Type: {client_type}
25 - Priority Level: {priority}
26 - Contact Email: {user_email}
27
28 {"HIGH PRIORITY - Expedited delivery required" if priority == "high" else "Standard delivery timeline"}
29
30 Please create a detailed, actionable content plan.
31 """
32
33 response = content_planner.run(planning_prompt)
34
35 enhanced_content = f"""
36 ## Strategic Content Plan
37
38 **Planning Topic:** {message}
39 **Client Details:** {client_type} | {priority.upper()} priority | {user_email}
40
41 **Content Strategy:**
42 {response.content}
43 """
44
45 return StepOutput(content=enhanced_content)
46
47# Define workflow with steps
48workflow = Workflow(
49 name="Content Creation Workflow",
50 steps=[
51 Step(name="Research Step", team=research_team),
52 Step(name="Content Planning Step", executor=custom_content_planning_function),
53 ]
54)
55
56# Run workflow with additional_data
57workflow.print_response(
58 input="AI trends in 2024",
59 additional_data={
60 "user_email": "michael@dundermifflin.com",
61 "priority": "high",
62 "client_type": "enterprise",
63 "budget": "$50000",
64 "deadline": "2024-12-15"
65 },
66 markdown=True,
67 stream=True
68)

Developer Resources