Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Date Agent

A minimal example demonstrating how to build an agent with OpenSymbolicAI that calculates days between dates.

What This Example Shows

This example demonstrates the core concepts of OpenSymbolicAI:

  • PlanExecute blueprint: 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

How It Works

The DateAgent class defines two primitives:

  1. today() - Returns the current date in ISO format
  2. daysBetween(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:

  1. Creates a plan using the available primitives
  2. Executes the plan step by step
  3. Returns the result

Prerequisites

  • Node.js 18+
  • Ollama running locally (or configure a different LLM provider)

Run

# 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?"

Expected Output

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

Customization

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