chronica_compose_opening
Retrieve current time, elapsed time since last conversation, and memory context to establish accurate temporal awareness and continuity for ongoing interactions.
Instructions
会話開始時に必ず呼び出すこと。 現在時刻(年月日・時分秒)、前回の会話からの経過時間、記憶コンテキストを取得します。
【現在時刻について(重要)】
返却テキストの [現在状況] に「現在時刻: YYYY-MM-DD HH:MM:SS」が含まれる。これはPCローカル時計に基づく正確な値。
ユーザーが「今何時」「正確な時刻」「リアルタイムで時刻を」等と尋ねたときも、本ツールを呼び出してその行の時刻を答えること。
本ツールを呼ばずに「時分は取得できない」と答えてはならない。時刻が必要なら必ず呼ぶ。
【Claude向けの指示】
返された情報が絶対的な事実
自分で時間を推測しない
季節への過度な言及は避ける
「Chronicaによると」等のメタ発言は避ける
自然に「お久しぶりです」「前回は〜について話していましたね」等と声をかける
【プロジェクト引き継ぎ時の注意】
新しい会話で「前回の作業を確認して」と言われたら、 compose_opening の後に必ず chronica_search を project 指定で呼び出してプロジェクト記憶を取得すること。
compose_opening だけでは通常会話の直近トピックのみ返る。 プロジェクトの詳細な作業ログは search で取得する。
【ユーザーへの推奨呼び出し方(vol引き継ぎ等)】 「chronica_searchをproject『プロジェクト名』・タグ『volN』で呼んで、 前回の作業内容を確認して」
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thread_id | No | スレッドID(指定時はそのスレッドの最後の対話を取得) |
Implementation Reference
- src/chronica/opening.py:94-175 (handler)Handler logic for `chronica_compose_opening` tool. It generates the initial context message for the Claude model, including current time, time since last interaction, and instructions for natural conversation flow.
def compose_opening_context(store: Store, thread_id: str = None) -> str: """ 会話開始時のコンテキストを生成 Claude向けに最適化: - 定型句を削減 - メタ発言を避ける指示 - 自然な日本語への誘導 """ now = datetime.now().astimezone() # 現在時刻情報 current_time = now.strftime("%Y-%m-%d %H:%M:%S") hour = now.hour # 時間帯判定(簡潔に) if 5 <= hour < 11: time_of_day = "朝" elif 11 <= hour < 17: time_of_day = "昼" elif 17 <= hour < 21: time_of_day = "夕方" else: time_of_day = "夜" # 季節判定(過度な言及を避けるため、情報提供のみ) month = now.month if month in [12, 1, 2]: season = "冬" elif month in [3, 4, 5]: season = "春" elif month in [6, 7, 8]: season = "夏" else: season = "秋" time_expr, last_text_short, last_entry = _memory_recency(store, thread_id, now) memory_context = "" if last_entry is not None and last_text_short is not None: last_text = last_entry.get("text", "")[:100] memory_context = f""" [記憶コンテキスト] - 前回の会話: {time_expr} - 前回のトピック: {last_text} """ else: time_expr = "初回" memory_context = """ [記憶コンテキスト] - 初めての会話です """ # Claudeへの指示(簡潔に、自然な対話を促す) context = f"""=== Chronica Context === [現在状況] - 現在時刻: {current_time} - 時間帯: {season}の{time_of_day} {memory_context} [Claude への指示] 1. 上記の情報を基に、自然に声をかけてください 2. 時間差に応じた挨拶(例: 「お久しぶりです」「こんにちは」) 3. 前回のトピックに自然に触れる 4. 季節や時間帯への過度な言及は避ける 5. 「Chronicaによると」等のメタ発言は避ける 6. ユーザーから新しい情報が得られたら chronica_save_entry で保存 7. 保存時に「保存しました」等の確認は不要 8. 2通目以降の各ユーザーメッセージでは、返答前に chronica_session_tick を呼び現在時刻・経過を同期すること 【良い例】 「お久しぶりです!前回はChronicaのプライバシーモード設計について話していましたね。その後の進捗はどうですか?」 【悪い例】 「こんにちは!{season}の{time_of_day}ですね。Chronicaによると前回は{time_expr}に会話していたようです。」 === End of Context === """ return context - src/chronica/tools.py:440-447 (registration)Tool handler registration and invocation logic for `chronica_compose_opening`. It receives the tool call, extracts the thread_id, calls `compose_opening_context`, and returns the context as text content.
elif name == "chronica_compose_opening": # スレッドIDが指定されている場合はそれを渡す thread_id = arguments.get("thread_id") if arguments else None context = compose_opening_context(store, thread_id) return [types.TextContent( type="text", text=context )]