openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

[Agent] Inject device, timezone, and user context into prompts; stop redundant ‘what timezone?’ questions

Open senamakel opened this issue 7 months ago • 1 comments

Summary

Agents should always receive reliable ambient context in the system prompt: device, local date/time with IANA timezone, and authenticated user identity fields (as available), so they do not ask the user for information the app already has. Example: requesting a morning briefing should not elicit “what timezone are you in?” when the desktop app controls the device and can supply that data.

Problem

  • User impact: Friction and loss of trust — the model appears unaware of the environment even though the product runs on the user’s machine with a logged-in account.
  • Concrete gap (morning briefing): The morning_briefing built-in agent assembles its system prompt in src/openhuman/agent/agents/morning_briefing/prompt.rs from the archetype + render_user_files, render_tools, and render_workspace only. It does not include the shared ## Current Date & Time block (DateTimeSection in src/openhuman/agent/prompts/mod.rs, exposed as render_datetime) or ## Runtime (RuntimeSection / render_runtime). So the model has no explicit “now” / timezone / host context in that prompt path.
  • General pattern: Per-agent prompt.rs builders opt in per section; any agent that omits datetime/runtime is likely to hallucinate a gap and ask the user.
  • Core vs machine TZ: DateTimeSection today uses chrono::Local in the core process (DateTimeSection::build). Depending on how the openhuman sidecar is launched, Local may or may not match the user’s OS timezone; the authoritative value for product UX is ideally the desktop app–reported IANA zone (Tauri/JS) plus optional OS locale.

Solution direction

  1. Standard “ambient” block — Add a small, cache-stable (or per-turn) section, e.g. ## User & device, injected for all or whitelisted built-ins, containing:
    • Current time: ISO-8601 + human-readable in the user’s timezone
    • IANA timezone string (e.g. America/Los_Angeles)
    • Device / OS summary (align with RuntimeSection: host, OS; optionally app version)
    • User: name / email / id from the authenticated session (openhuman.auth_get_me / backend), redacted as needed for logs
  2. Plumb timezone from the shell — Extend config or session so the ** renderer** (Tauri) reports Intl / system timezone to the core on startup or before agent runs, if chrono::Local is insufficient in CI/edge cases.
  3. Fix morning_briefing prompt assembly — At minimum, call render_datetime and render_runtime (or the new combined section) in morning_briefing/prompt.rs so the briefing agent sees “now” and environment without tool calls.
  4. Prompt copy — In archetype prompts (e.g. morning_briefing/prompt.md), one line: “You are given the user’s local time and timezone in the system message — do not ask the user for their timezone unless the system context is missing.”
  5. Audits — Other omit_identity = true agents that use custom prompt.rs (welcome, orchestrator, etc.): ensure they still get datetime/ambient where appropriate.

Acceptance criteria

  • [ ] Morning briefing no longer asks for the user’s timezone in normal operation when the app can supply it; validated manually or with a small prompt fixture test.
  • [ ] System prompt for targeted agents includes explicit local time + IANA timezone + device OS/host (or references a single ## User & device block).
  • [ ] User/session fields from the backend (non-secret) are available to the prompt layer via PromptContext or equivalent — not only workspace files.
  • [ ] Privacy / logs — Document what is embedded; never dump tokens; follow existing redaction rules in AGENTS.md.
  • [ ] Tests — Unit test that morning_briefing’s build() output contains the datetime/tz section (or new ambient section) when wired.

Related code

  • src/openhuman/agent/agents/morning_briefing/prompt.rs — missing render_datetime / render_runtime / user ambient
  • src/openhuman/agent/prompts/mod.rs — DateTimeSection, RuntimeSection, PromptContext
  • src/openhuman/agent/prompts/mod.rs (GLOBAL_STYLE) — where global suffix lives; new section ordering must respect KV-cache notes in file headers
  • app/src/services/api/userApi.ts — getMe for user fields in UI; parallel path for core may be needed
  • src/openhuman/cron/seed.rs — morning briefing cron copy mentions local time; prompt should match

senamakel avatar Apr 26 '26 04:04 senamakel

@senamakel picked this — PR #959. scoped to morning_briefing per the issue. noticed the same gap (no datetime/runtime/user block) exists in 14 other custom agent prompt builders — kept it out for review surface, happy to do a follow-up if you want it.

obchain avatar Apr 27 '26 07:04 obchain