A minimal example demonstrating how to build an agent with OpenSymbolicAI that calculates days between dates.
This example demonstrates the core concepts of OpenSymbolicAI:
PlanExecuteblueprint: A base class for agents that plan before executing@primitive: Marks methods as atomic operations the agent can use@decomposition: Provides example task breakdowns to guide the LLM
The DateAgent class defines two primitives:
today()- Returns the current date in ISO formatdaysBetween(start, end)- Calculates the number of days between two dates
When you run a query like "How many days from Jan 1, 2026 to Valentine's Day 2026?", the agent:
- Creates a plan using the available primitives
- Executes the plan step by step
- Returns the result
- Node.js 18+
- Ollama running locally (or configure a different LLM provider)
# From the examples-ts directory
npm run date-agent
# Or with a custom query
npx tsx examples/date_agent/main.ts "How many days until Christmas 2025?"Using model: ollama/qwen3:4b
Query: How many days from Jan 1, 2026 to Valentine's Day 2026?
────────────────────────────────────────
Plan:
────────────────────────────────────────
1. Parse "Jan 1, 2026" as start date: 2026-01-01
2. Parse "Valentine's Day 2026" as end date: 2026-02-14
3. Call daysBetween("2026-01-01", "2026-02-14")
────────────────────────────────────────
Result:
────────────────────────────────────────
44
To use a different LLM provider, set environment variables:
# For OpenAI
LLM_PROVIDER=openai LLM_MODEL=gpt-4 npm run date-agent
# For Anthropic
LLM_PROVIDER=anthropic LLM_MODEL=claude-3-sonnet-20240229 npm run date-agent
# For Groq
LLM_PROVIDER=groq LLM_MODEL=llama-3.1-70b-versatile npm run date-agent