Skip to main content
LLMs don’t know the current date, who your user is, or what plan they’re on. You need to inject this information into the agent’s context. This page covers the most common patterns for working with dynamic data in production agents.

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
If you build the instructions at module load time (outside main()), the date will be set when the agent starts and won’t update between requests. For most use cases this is fine since deploys are frequent. If you need per-request dates, see the next pattern.

Per-Request Dynamic Instructions

When you need the date to be accurate on every single request, rebuild instructions inside main():
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

These messages are prepended to the conversation, so the agent sees them as context before the user’s message.

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

A good rule of thumb: put behavior rules in instructions and data in messages. The instructions tell the agent how to behave; the messages tell it what it’s working with.

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
In the portal, your prompt template would look like:
Use loadPrompt() when you want non-developers (product managers, prompt engineers) to edit prompts through the portal without code changes. Use local functions when the prompt logic is complex or involves conditionals.

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

Never trust the LLM to calculate dates. Always validate dates in your tools — check for past dates, weekends, business hours, and conflicts. The LLM should propose, your tool should validate.

Next Steps

Prompts

Manage prompts with loadPrompt()

Tools

Build validation tools

Best Practices

Tips for effective agents

Context Management

User identification patterns