Skip to content

Add KnowsCurrentTime capability#170

Draft
DouweM wants to merge 2 commits intomainfrom
capability/knows-current-time
Draft

Add KnowsCurrentTime capability#170
DouweM wants to merge 2 commits intomainfrom
capability/knows-current-time

Conversation

@DouweM
Copy link
Copy Markdown
Contributor

@DouweM DouweM commented Apr 10, 2026

Summary

  • Adds KnowsCurrentTime, a minimal AbstractCapability subclass that injects the current date/time into the system prompt via get_instructions()
  • Configurable tz (IANA timezone, default UTC), format (strftime string), and include_tool (optional get_current_time tool)
  • Exported from pydantic_harness package: from pydantic_harness import KnowsCurrentTime
  • Adds tzdata dependency for cross-platform timezone support
  • Points pydantic-ai-slim to git main branch (capabilities API not yet released to PyPI)

Closes #23

Test plan

  • 16 tests covering all code paths (helpers, defaults, instructions, toolset, serialization, from_spec)
  • 100% code coverage
  • ruff lint + format clean
  • pyright strict mode clean

🤖 Generated with Claude Code

DouweM and others added 2 commits April 2, 2026 05:34
A minimal AbstractCapability subclass that injects the current date/time
into the system prompt via get_instructions(), with optional get_current_time
tool. Configurable timezone and strftime format.

Closes #23

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Invalid IANA timezone names now raise a ValueError with a helpful
message and examples, rather than letting a raw KeyError propagate
from ZoneInfo.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review


Returns a string like::

The current date and time is: 2026-04-02T20:30:00Z (Wednesday, April 2, 2026)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Docstring example shows wrong day of week (Wednesday instead of Thursday)

The docstring example at line 27 claims April 2, 2026 is a "Wednesday", but it is actually a Thursday. The code itself uses strftime("%A") so it produces the correct day at runtime, and the test at tests/test_knows_current_time.py:40 correctly asserts "Thursday". This makes the docstring inconsistent with both the code's actual output and the tests.

Suggested change
The current date and time is: 2026-04-02T20:30:00Z (Wednesday, April 2, 2026)
The current date and time is: 2026-04-02T20:30:00Z (Thursday, April 2, 2026)
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +55 to +56
format: str = '%Y-%m-%dT%H:%M:%SZ'
"""``strftime`` format string for the datetime."""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Default format string includes literal 'Z' (UTC designator) that is misleading for non-UTC timezones

The default format is '%Y-%m-%dT%H:%M:%SZ' which includes a literal Z at the end — the ISO 8601 UTC designator. When a user configures KnowsCurrentTime(tz='America/New_York') without also changing format, the output will be e.g. 2026-04-02T16:30:00Z which falsely claims the time is UTC. The LLM would then interpret this as UTC rather than Eastern time.

This is not a runtime crash, and the default tz='UTC' + default format combination is internally consistent, so the defaults work correctly together. However, users who only customize tz will get semantically incorrect ISO 8601 output. Consider either documenting this limitation clearly, or using %z in the format to auto-append the correct offset (e.g. -0400), or programmatically adjusting the suffix based on the timezone.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@DouweM
Copy link
Copy Markdown
Contributor Author

DouweM commented Apr 10, 2026

Originally posted by @DouweM in #159 comment (PR closed due to history rewrite)

Audit vs prior art: KnowsCurrentTime

Worth adding now:

  • Timezone validation at init time
  • Elapsed time since session start

Follow-up opportunities:

  • Scheduling hints

@DouweM DouweM marked this pull request as draft April 10, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KnowsCurrentTime capability

1 participant