The Problem
Without dynamic data, your agent is blind to reality:Injecting Current Date and Time
The most common issue: LLMs don’t know today’s date. Always inject it into the instructions.Using a Function for Instructions
Instead of a static string, use a function that builds the instructions dynamically:agent.ts
Per-Request Dynamic Instructions
When you need the date to be accurate on every single request, rebuild instructions insidemain():
main.ts
Injecting Context via messages
The agent.process() method accepts a messages array alongside message. Use it to inject structured context — user profile data, CRM records, previous interactions, or any information the agent needs to respond well.
Basic Pattern
Fetching Context Dynamically in main.ts
The most common pattern: fetch data from your database or CRM and inject it as context messages.
main.ts
Combining messages with Date Context
You can use both buildInstructions() for the system prompt and messages for per-request context:
main.ts
When to Use messages vs instructions
Injecting User Context
Pass user-specific information into the instructions so the agent knows who it’s talking to:Basic User Info
main.ts
With Debt/Financial Info (Collections)
main.ts
Using loadPrompt() with Variables
For prompts managed in the Runflow portal, use loadPrompt() with template variables:
agent.ts
Date Handling for Scheduling
Scheduling is one of the hardest tasks for LLMs. Here are patterns that work in production.Always Provide Today’s Date
The single most important thing: always tell the LLM what today’s date is.Scheduling Tool with Date Validation
Don’t trust the LLM to calculate dates correctly. Validate in the tool:tools/schedule-appointment.ts
Availability Check Tool
Let the agent check available slots instead of guessing:tools/check-availability.ts
Combining Everything: Scheduling Agent
A complete example that combines date injection, user context, and scheduling tools:main.ts
Summary
Next Steps
Prompts
Manage prompts with loadPrompt()
Tools
Build validation tools
Best Practices
Tips for effective agents
Context Management
User identification patterns