diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-06-26 14:39:23 +0200 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-06-26 14:39:23 +0200 |
| commit | 963f59569437fe43a49ce36a003a143fa2f767c8 (patch) | |
| tree | 968b0dad13193536770ae1e6b580b27e22f9366b /agent/orchestrator/context.py | |
| parent | 741a04c2abcbd77451c0933a19d91fddb9982882 (diff) | |
| download | senia-963f59569437fe43a49ce36a003a143fa2f767c8.tar.xz senia-963f59569437fe43a49ce36a003a143fa2f767c8.zip | |
created custom agent loop
Diffstat (limited to 'agent/orchestrator/context.py')
| -rw-r--r-- | agent/orchestrator/context.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/agent/orchestrator/context.py b/agent/orchestrator/context.py new file mode 100644 index 0000000..f8679ff --- /dev/null +++ b/agent/orchestrator/context.py @@ -0,0 +1,42 @@ +"""Builds the dynamic per-turn context. + +This handles things that change per turn: the current time, today's diary +entries, open tasks. Persona is NOT here; that's a backend configuration +concern (see models/claude_code.py docstring). +""" + +import sqlite3 +from datetime import datetime, timezone +from pathlib import Path + + +SENIA_DB = Path("/etc/senia/data/senia.db") + + +def _today_diary_entries() -> list[str]: + if not SENIA_DB.exists(): + return [] + now = datetime.now(timezone.utc).astimezone() + start = now.replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + conn = sqlite3.connect(SENIA_DB) + try: + return [ + f"- {row[0]} - {row[1]}" + for row in conn.execute( + "SELECT ts, content FROM diary_logs WHERE ts >= ? ORDER BY ts", + (start,), + ).fetchall() + ] + finally: + conn.close() + + +def build_turn_context() -> str: + diary = _today_diary_entries() + diary_section = ( + "## Today's diary so far\n\n" + "\n".join(diary) + if diary + else "## Today's diary so far\n\n(no entries yet today)" + ) + now = datetime.now(timezone.utc).astimezone().isoformat(timespec="seconds") + return f"## Current time\n\n{now}\n\n{diary_section}" |
