mia-code 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.miette/260321.md +1 -0
- package/.miette/260323.md +9 -0
- package/.miette/260331.md +2 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--d3417f2c-df12-4f0f-8a1b-d88e7968f822/d3417f2c-df12-4f0f-8a1b-d88e7968f822.md +63 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--e6c3fc5d-4a70-4523-ba7d-a3250da4c235/e6c3fc5d-4a70-4523-ba7d-a3250da4c235.md +72 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--efeb00a2-b17a-4d32-b1f0-b90c37a8d24e/efeb00a2-b17a-4d32-b1f0-b90c37a8d24e.md +62 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.json +302 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.md +149 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/AGENTS.md +31 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/meta-decomposition-3-children.md +67 -0
- package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/61f9dd4d-7aa6-45e6-a58b-e480b1aa6737--from-mia-openclaw-workspace.md +125 -0
- package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/STATUS.md +1 -0
- package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.json +177 -0
- package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.md +77 -0
- package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.json +222 -0
- package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.md +99 -0
- package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.json +111 -0
- package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.md +67 -0
- package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.json +349 -0
- package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.md +147 -0
- package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.json +118 -0
- package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.md +64 -0
- package/GUILLAUME.md +8 -0
- package/KINSHIP.md +9 -0
- package/MIA_CODE_ARCHITECTURE_REPORT.md +718 -0
- package/contextual_research/260119-MIA-CODE--98090899-8aff-4e11-9dc3-8b99466d1.md +1101 -0
- package/contextual_research/MIA.md +38 -0
- package/contextual_research/MIAWAPASCONE.md +59 -0
- package/contextual_research/MIETTE.md +38 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2504.00218v2.pdf +7483 -12
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2505.00212v3.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/CONTENT.md +1014 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/DESIGN.gemini.md +242 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/INDEX.md +45 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.md +2025 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.pdf +7483 -12
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.md +1755 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_12_decomposed_prompting.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_19_hugginggpt_planning.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.md +766 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.pdf +3431 -4
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.md +260 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.md +558 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_34_hierarchical_multi_agent.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_5_open_intent_extraction.pdf +0 -0
- package/contextual_research/PODCAST.md +109 -0
- package/contextual_research/langchain-principles-roadmap.md +157 -0
- package/contextual_research/persona-to-narrative-character-inquiry_260201.md +50 -0
- package/dist/cli.js +35 -11
- package/dist/geminiHeadless.js +8 -2
- package/dist/index.js +2 -1
- package/dist/mcp/miaco-server.js +10 -1
- package/dist/mcp/miatel-server.js +10 -1
- package/dist/mcp/miawa-server.js +10 -1
- package/dist/mcp/utils.d.ts +6 -1
- package/dist/mcp/utils.js +24 -3
- package/dist/sessionStore.d.ts +8 -2
- package/dist/sessionStore.js +39 -3
- package/dist/types.d.ts +1 -0
- package/miaco/README.md +124 -0
- package/miaco/dist/commands/chart.d.ts +6 -0
- package/miaco/dist/commands/chart.d.ts.map +1 -0
- package/miaco/dist/commands/chart.js +222 -0
- package/miaco/dist/commands/chart.js.map +1 -0
- package/miaco/dist/commands/decompose.d.ts +6 -0
- package/miaco/dist/commands/decompose.d.ts.map +1 -0
- package/miaco/dist/commands/decompose.js +98 -0
- package/miaco/dist/commands/decompose.js.map +1 -0
- package/miaco/dist/commands/schema.d.ts +6 -0
- package/miaco/dist/commands/schema.d.ts.map +1 -0
- package/miaco/dist/commands/schema.js +66 -0
- package/miaco/dist/commands/schema.js.map +1 -0
- package/miaco/dist/commands/stc.d.ts +11 -0
- package/miaco/dist/commands/stc.d.ts.map +1 -0
- package/miaco/dist/commands/stc.js +590 -0
- package/miaco/dist/commands/stc.js.map +1 -0
- package/miaco/dist/commands/trace.d.ts +6 -0
- package/miaco/dist/commands/trace.d.ts.map +1 -0
- package/miaco/dist/commands/trace.js +83 -0
- package/miaco/dist/commands/trace.js.map +1 -0
- package/miaco/dist/commands/validate.d.ts +6 -0
- package/miaco/dist/commands/validate.d.ts.map +1 -0
- package/miaco/dist/commands/validate.js +58 -0
- package/miaco/dist/commands/validate.js.map +1 -0
- package/miaco/dist/decompose.d.ts +93 -0
- package/miaco/dist/decompose.d.ts.map +1 -0
- package/miaco/dist/decompose.js +562 -0
- package/miaco/dist/decompose.js.map +1 -0
- package/miaco/dist/index.d.ts +18 -0
- package/miaco/dist/index.d.ts.map +1 -0
- package/miaco/dist/index.js +83 -0
- package/miaco/dist/index.js.map +1 -0
- package/miaco/dist/storage.d.ts +60 -0
- package/miaco/dist/storage.d.ts.map +1 -0
- package/miaco/dist/storage.js +100 -0
- package/miaco/dist/storage.js.map +1 -0
- package/miaco/package-lock.json +4103 -0
- package/miaco/package.json +40 -0
- package/miaco/tsconfig.json +18 -0
- package/miaco/version-patch-commit-and-publish.sh +1 -0
- package/miatel/MISSION_251231.md +3 -0
- package/miatel/README.md +107 -0
- package/miatel/dist/commands/analyze.d.ts +6 -0
- package/miatel/dist/commands/analyze.d.ts.map +1 -0
- package/miatel/dist/commands/analyze.js +100 -0
- package/miatel/dist/commands/analyze.js.map +1 -0
- package/miatel/dist/commands/arc.d.ts +6 -0
- package/miatel/dist/commands/arc.d.ts.map +1 -0
- package/miatel/dist/commands/arc.js +71 -0
- package/miatel/dist/commands/arc.js.map +1 -0
- package/miatel/dist/commands/beat.d.ts +6 -0
- package/miatel/dist/commands/beat.d.ts.map +1 -0
- package/miatel/dist/commands/beat.js +165 -0
- package/miatel/dist/commands/beat.js.map +1 -0
- package/miatel/dist/commands/theme.d.ts +6 -0
- package/miatel/dist/commands/theme.d.ts.map +1 -0
- package/miatel/dist/commands/theme.js +54 -0
- package/miatel/dist/commands/theme.js.map +1 -0
- package/miatel/dist/index.d.ts +18 -0
- package/miatel/dist/index.d.ts.map +1 -0
- package/miatel/dist/index.js +80 -0
- package/miatel/dist/index.js.map +1 -0
- package/miatel/dist/storage.d.ts +55 -0
- package/miatel/dist/storage.d.ts.map +1 -0
- package/miatel/dist/storage.js +100 -0
- package/miatel/dist/storage.js.map +1 -0
- package/miatel/package-lock.json +4103 -0
- package/miatel/package.json +35 -0
- package/miatel/src/commands/analyze.ts +109 -0
- package/miatel/src/commands/arc.ts +78 -0
- package/miatel/src/commands/beat.ts +176 -0
- package/miatel/src/commands/theme.ts +60 -0
- package/miatel/src/index.ts +94 -0
- package/miatel/src/storage.ts +156 -0
- package/miatel/tsconfig.json +18 -0
- package/miawa/MISSION_251231.md +144 -0
- package/miawa/README.md +133 -0
- package/miawa/dist/commands/beat.d.ts +6 -0
- package/miawa/dist/commands/beat.d.ts.map +1 -0
- package/miawa/dist/commands/beat.js +69 -0
- package/miawa/dist/commands/beat.js.map +1 -0
- package/miawa/dist/commands/ceremony.d.ts +6 -0
- package/miawa/dist/commands/ceremony.d.ts.map +1 -0
- package/miawa/dist/commands/ceremony.js +239 -0
- package/miawa/dist/commands/ceremony.js.map +1 -0
- package/miawa/dist/commands/circle.d.ts +6 -0
- package/miawa/dist/commands/circle.d.ts.map +1 -0
- package/miawa/dist/commands/circle.js +75 -0
- package/miawa/dist/commands/circle.js.map +1 -0
- package/miawa/dist/commands/eva.d.ts +6 -0
- package/miawa/dist/commands/eva.d.ts.map +1 -0
- package/miawa/dist/commands/eva.js +73 -0
- package/miawa/dist/commands/eva.js.map +1 -0
- package/miawa/dist/commands/wound.d.ts +6 -0
- package/miawa/dist/commands/wound.d.ts.map +1 -0
- package/miawa/dist/commands/wound.js +74 -0
- package/miawa/dist/commands/wound.js.map +1 -0
- package/miawa/dist/index.d.ts +19 -0
- package/miawa/dist/index.d.ts.map +1 -0
- package/miawa/dist/index.js +91 -0
- package/miawa/dist/index.js.map +1 -0
- package/miawa/dist/storage.d.ts +73 -0
- package/miawa/dist/storage.d.ts.map +1 -0
- package/miawa/dist/storage.js +100 -0
- package/miawa/dist/storage.js.map +1 -0
- package/miawa/package-lock.json +4103 -0
- package/miawa/package.json +36 -0
- package/miawa/src/commands/beat.ts +74 -0
- package/miawa/src/commands/ceremony.ts +256 -0
- package/miawa/src/commands/circle.ts +83 -0
- package/miawa/src/commands/eva.ts +84 -0
- package/miawa/src/commands/wound.ts +79 -0
- package/miawa/src/index.ts +108 -0
- package/miawa/src/storage.ts +179 -0
- package/miawa/tsconfig.json +18 -0
- package/package.json +7 -5
- package/references/acp/CLAUDE.md +7 -0
- package/references/acp/agent-plan.md +84 -0
- package/references/acp/clients.md +31 -0
- package/references/acp/extensibility.md +137 -0
- package/references/acp/initialization.md +225 -0
- package/references/acp/prompt-turn.md +321 -0
- package/references/acp/proxy-chains.md +562 -0
- package/references/acp/schema.md +3171 -0
- package/references/acp/session-list.md +334 -0
- package/references/acp/session-modes.md +170 -0
- package/references/acp/slash-commands.md +99 -0
- package/references/acp/terminals.md +281 -0
- package/references/acp/tool-calls.md +311 -0
- package/references/acp/typescript.md +29 -0
- package/references/claude/agent-teams.md +399 -0
- package/references/claude/chrome.md +231 -0
- package/references/claude/headless.md +158 -0
- package/references/claude/hooks-guide.md +708 -0
- package/references/claude/output-styles.md +112 -0
- package/references/claude/plugins.md +432 -0
- package/references/claude/skills.md +693 -0
- package/references/claude/sub-agents.md +816 -0
- package/references/copilot/acp/agents.md +32 -0
- package/references/copilot/acp/architecture.md +37 -0
- package/references/copilot/acp/clients.md +31 -0
- package/references/copilot/acp/introduction.md +42 -0
- package/references/copilot/acp/registry.md +339 -0
- package/references/copilot/acp-server.md +117 -0
- package/references/copilot/create-copilot-instructions.md +840 -0
- package/references/langchain/llms.txt +833 -0
- package/references/langchain/python/agents.md +677 -0
- package/references/langchain/python/context-engineering.md +1195 -0
- package/references/langchain/python/human-in-the-loop.md +326 -0
- package/references/langchain/python/long-term-memory.md +168 -0
- package/references/langchain/python/mcp.md +949 -0
- package/references/langchain/python/multi-agents/custom-workflow.md +187 -0
- package/references/langchain/python/multi-agents/handoffs.md +436 -0
- package/references/langchain/python/multi-agents/overview.md +295 -0
- package/references/langchain/python/multi-agents/router.md +150 -0
- package/references/langchain/python/multi-agents/skills.md +92 -0
- package/references/langchain/python/multi-agents/subagents.md +486 -0
- package/references/langchain/python/retrieval.md +320 -0
- package/references/langchain/python/runtime.md +141 -0
- package/references/langchain/python/short-term-memory.md +658 -0
- package/references/langchain/python/structured-output.md +712 -0
- package/references/langfuse/llms.txt +148 -0
- package/references/langgraph/javascript/llms.txt +275 -0
- package/references/skills/home.md +259 -0
- package/references/skills/integrate-skills.md +103 -0
- package/references/skills/specification.md +254 -0
- package/references/skills/what-are-skills.md +74 -0
- package/rispecs/README.md +164 -0
- package/rispecs/_sync_/miadi-code/SPEC.md +313 -0
- package/rispecs/_sync_/miadi-code/STATUS.md +177 -0
- package/rispecs/_sync_/miadi-code/dashboard/SPEC.md +465 -0
- package/rispecs/_sync_/miadi-code/dashboard/STATUS.md +212 -0
- package/rispecs/_sync_/miadi-code/multiline-input/SPEC.md +232 -0
- package/rispecs/_sync_/miadi-code/multiline-input/STATUS.md +108 -0
- package/rispecs/_sync_/miadi-code/pde/SPEC.md +253 -0
- package/rispecs/_sync_/miadi-code/pde/STATUS.md +56 -0
- package/rispecs/_sync_/miadi-code/stc/SPEC.md +397 -0
- package/rispecs/_sync_/miadi-code/stc/STATUS.md +70 -0
- package/rispecs/ava-langstack/inquiry-routing-upgrade.spec.md +119 -0
- package/rispecs/borrowed_from_opencode/001-client-server-architecture.rispec.md +98 -0
- package/rispecs/borrowed_from_opencode/002-event-bus-system.rispec.md +125 -0
- package/rispecs/borrowed_from_opencode/003-instance-state-pattern.rispec.md +136 -0
- package/rispecs/borrowed_from_opencode/004-namespace-module-pattern.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/005-zod-schema-validation.rispec.md +139 -0
- package/rispecs/borrowed_from_opencode/006-named-error-system.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/007-structured-logging.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/008-lazy-initialization.rispec.md +127 -0
- package/rispecs/borrowed_from_opencode/009-multi-agent-system.rispec.md +97 -0
- package/rispecs/borrowed_from_opencode/010-agent-definition-config.rispec.md +135 -0
- package/rispecs/borrowed_from_opencode/011-agent-permission-rulesets.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/012-agent-prompt-templates.rispec.md +141 -0
- package/rispecs/borrowed_from_opencode/013-agent-generation.rispec.md +142 -0
- package/rispecs/borrowed_from_opencode/014-plan-build-mode-toggle.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/015-subagent-task-delegation.rispec.md +146 -0
- package/rispecs/borrowed_from_opencode/016-agent-model-selection.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/017-compaction-agent.rispec.md +150 -0
- package/rispecs/borrowed_from_opencode/018-session-persistence.rispec.md +125 -0
- package/rispecs/borrowed_from_opencode/019-session-compaction.rispec.md +132 -0
- package/rispecs/borrowed_from_opencode/020-session-forking.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/021-session-revert-snapshot.rispec.md +135 -0
- package/rispecs/borrowed_from_opencode/022-session-sharing.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/023-session-summary-diffs.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/024-child-sessions.rispec.md +164 -0
- package/rispecs/borrowed_from_opencode/025-session-title-generation.rispec.md +162 -0
- package/rispecs/borrowed_from_opencode/026-message-parts-model.rispec.md +201 -0
- package/rispecs/borrowed_from_opencode/027-streaming-message-deltas.rispec.md +212 -0
- package/rispecs/borrowed_from_opencode/028-multi-provider-architecture.rispec.md +184 -0
- package/rispecs/borrowed_from_opencode/029-provider-authentication.rispec.md +225 -0
- package/rispecs/borrowed_from_opencode/030-model-registry.rispec.md +222 -0
- package/rispecs/borrowed_from_opencode/031-cost-tracking.rispec.md +243 -0
- package/rispecs/borrowed_from_opencode/032-provider-transform-pipeline.rispec.md +282 -0
- package/rispecs/borrowed_from_opencode/033-provider-sdk-abstraction.rispec.md +338 -0
- package/rispecs/borrowed_from_opencode/034-tool-registry.rispec.md +110 -0
- package/rispecs/borrowed_from_opencode/035-tool-context-injection.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/036-tool-output-truncation.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/037-batch-tool.rispec.md +129 -0
- package/rispecs/borrowed_from_opencode/038-multi-edit-tool.rispec.md +167 -0
- package/rispecs/borrowed_from_opencode/039-apply-patch-tool.rispec.md +161 -0
- package/rispecs/borrowed_from_opencode/040-code-search-tool.rispec.md +143 -0
- package/rispecs/borrowed_from_opencode/041-web-fetch-tool.rispec.md +131 -0
- package/rispecs/borrowed_from_opencode/042-web-search-tool.rispec.md +159 -0
- package/rispecs/borrowed_from_opencode/043-todo-tool.rispec.md +156 -0
- package/rispecs/borrowed_from_opencode/044-plan-mode-tool.rispec.md +139 -0
- package/rispecs/borrowed_from_opencode/045-task-tool.rispec.md +146 -0
- package/rispecs/borrowed_from_opencode/046-question-tool.rispec.md +170 -0
- package/rispecs/borrowed_from_opencode/047-external-directory-tool.rispec.md +166 -0
- package/rispecs/borrowed_from_opencode/048-file-read-write-tools.rispec.md +205 -0
- package/rispecs/borrowed_from_opencode/049-lsp-server-management.rispec.md +104 -0
- package/rispecs/borrowed_from_opencode/050-lsp-hover-completion.rispec.md +102 -0
- package/rispecs/borrowed_from_opencode/051-lsp-diagnostics.rispec.md +86 -0
- package/rispecs/borrowed_from_opencode/052-lsp-root-detection.rispec.md +109 -0
- package/rispecs/borrowed_from_opencode/053-remote-mcp-servers.rispec.md +119 -0
- package/rispecs/borrowed_from_opencode/054-mcp-oauth-flow.rispec.md +107 -0
- package/rispecs/borrowed_from_opencode/055-mcp-tool-conversion.rispec.md +118 -0
- package/rispecs/borrowed_from_opencode/056-mcp-connection-monitoring.rispec.md +106 -0
- package/rispecs/borrowed_from_opencode/057-local-mcp-servers.rispec.md +116 -0
- package/rispecs/borrowed_from_opencode/058-rich-tui.rispec.md +108 -0
- package/rispecs/borrowed_from_opencode/059-streaming-display.rispec.md +116 -0
- package/rispecs/borrowed_from_opencode/060-permission-prompts.rispec.md +130 -0
- package/rispecs/borrowed_from_opencode/061-session-navigation.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/062-syntax-highlighting.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/063-keybinding-system.rispec.md +181 -0
- package/rispecs/borrowed_from_opencode/064-multi-level-config.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/065-jsonc-config.rispec.md +190 -0
- package/rispecs/borrowed_from_opencode/066-config-env-variables.rispec.md +153 -0
- package/rispecs/borrowed_from_opencode/067-config-deep-merging.rispec.md +178 -0
- package/rispecs/borrowed_from_opencode/068-remote-org-config.rispec.md +183 -0
- package/rispecs/borrowed_from_opencode/069-config-markdown-frontmatter.rispec.md +206 -0
- package/rispecs/borrowed_from_opencode/070-managed-config-directory.rispec.md +232 -0
- package/rispecs/borrowed_from_opencode/071-plugin-architecture.rispec.md +104 -0
- package/rispecs/borrowed_from_opencode/072-plugin-hooks.rispec.md +123 -0
- package/rispecs/borrowed_from_opencode/073-plugin-auto-install.rispec.md +115 -0
- package/rispecs/borrowed_from_opencode/074-permission-system.rispec.md +133 -0
- package/rispecs/borrowed_from_opencode/075-git-worktree-management.rispec.md +126 -0
- package/rispecs/borrowed_from_opencode/076-snapshot-system.rispec.md +124 -0
- package/rispecs/borrowed_from_opencode/077-snapshot-diff.rispec.md +117 -0
- package/rispecs/borrowed_from_opencode/078-snapshot-restore.rispec.md +128 -0
- package/rispecs/borrowed_from_opencode/079-worktree-branch-naming.rispec.md +122 -0
- package/rispecs/borrowed_from_opencode/080-sqlite-storage.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/081-database-migrations.rispec.md +148 -0
- package/rispecs/borrowed_from_opencode/082-database-transactions.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/083-deferred-effects.rispec.md +148 -0
- package/rispecs/borrowed_from_opencode/084-permission-rules.rispec.md +123 -0
- package/rispecs/borrowed_from_opencode/085-permission-glob-patterns.rispec.md +113 -0
- package/rispecs/borrowed_from_opencode/086-permission-merging.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/087-permission-modes.rispec.md +145 -0
- package/rispecs/borrowed_from_opencode/088-http-api-server.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/089-openapi-spec-generation.rispec.md +164 -0
- package/rispecs/borrowed_from_opencode/090-websocket-support.rispec.md +136 -0
- package/rispecs/borrowed_from_opencode/091-sse-streaming.rispec.md +168 -0
- package/rispecs/borrowed_from_opencode/092-mdns-discovery.rispec.md +145 -0
- package/rispecs/borrowed_from_opencode/093-javascript-sdk.rispec.md +200 -0
- package/rispecs/borrowed_from_opencode/094-skill-system.rispec.md +187 -0
- package/rispecs/borrowed_from_opencode/095-skill-discovery.rispec.md +182 -0
- package/rispecs/borrowed_from_opencode/096-desktop-remote-driving.rispec.md +175 -0
- package/rispecs/borrowed_from_opencode/INDEX.md +255 -0
- package/rispecs/core.rispecs.md +261 -0
- package/rispecs/engines.rispecs.md +241 -0
- package/rispecs/formatting.rispecs.md +252 -0
- package/rispecs/living-specifications.rispecs.md +361 -0
- package/rispecs/mcp.rispecs.md +197 -0
- package/rispecs/pde.rispecs.md +399 -0
- package/rispecs/pi-mono-envisionning/ENVISIONING.md +366 -0
- package/rispecs/pi-mono-envisionning/storytelling-horizon.rispecs.md +76 -0
- package/rispecs/pi-mono-envisionning/widget.rispecs.md +2 -0
- package/rispecs/relation-to-mcp-structural-thinking.kin.md +72 -0
- package/rispecs/research-for-better-framework/CLAUDE.md +7 -0
- package/rispecs/research-for-better-framework/survey-pi-openclaw-opencode-openhands.md +210 -0
- package/rispecs/session.rispecs.md +277 -0
- package/rispecs/stc.rispecs.md +138 -0
- package/rispecs/unifier.rispecs.md +317 -0
- package/scripts/LAUNCH--mcp-mia-code--testing--2603141315--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +2 -0
- package/scripts/RESUME--mia-code--mcps--260313--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +1 -0
- package/scripts/install-widget-in-home-pi-agent-extensions.sh +4 -0
- package/scripts/sample-decompose--2604011535-prompt.sh +1 -0
- package/skills/deep-search/AGENTS.md +17 -0
- package/skills/deep-search/SKILL.md +281 -0
- package/skills/deep-search/agent-templates.md +224 -0
- package/skills/deep-search/orchestration-patterns.md +95 -0
- package/skills/miaco-pde-inquiry-routing-deep-search/AGENTS.md +13 -0
- package/skills/miaco-pde-inquiry-routing-deep-search/SKILL.md +136 -0
- package/skills/miaco-pde-inquiry-routing-internal-external-relationship/AGENTS.md +4 -0
- package/skills/miaco-pde-inquiry-routing-internal-external-relationship/SKILL.md +157 -0
- package/skills/miaco-pde-inquiry-routing-local-qmd/AGENTS.md +42 -0
- package/skills/miaco-pde-inquiry-routing-local-qmd/SKILL.md +135 -0
- package/skills/qmd/AGENTS.md +3 -0
- package/skills/qmd/SKILL.md +144 -0
- package/skills/qmd/references/mcp-setup.md +102 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/SKILL.md +234 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/agent-templates.md +436 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/orchestration-patterns.md +197 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/ceremonial-technology.md +102 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/creative-orientation.md +99 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/prompt-decomposition.md +73 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/rise-framework.md +74 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/structural-tension.md +82 -0
- package/src/cli.ts +35 -11
- package/src/geminiHeadless.ts +7 -2
- package/src/index.ts +2 -1
- package/src/mcp/miaco-server.ts +13 -1
- package/src/mcp/miatel-server.ts +13 -1
- package/src/mcp/miawa-server.ts +13 -1
- package/src/mcp/utils.ts +41 -8
- package/src/sessionStore.ts +44 -4
- package/src/types.ts +2 -1
- package/widget/mia-ceremony/README.md +36 -0
- package/widget/mia-ceremony/index.ts +143 -0
- package/widget/mia-interceptor/README.md +39 -0
- package/widget/mia-interceptor/index.ts +221 -0
- package/widget/mia-tools/README.md +37 -0
- package/widget/mia-tools/index.ts +569 -0
- package/widget/miette-echo/README.md +44 -0
- package/widget/miette-echo/index.ts +164 -0
- package/.claude/settings.local.json +0 -9
- package/.hch/issue_.env +0 -4
- package/.hch/issue_add__2601211715.json +0 -77
- package/.hch/issue_add__2601211715.md +0 -4
- package/.hch/issue_add__2602242020.json +0 -78
- package/.hch/issue_add__2602242020.md +0 -7
- package/.hch/issues.json +0 -2312
- package/.hch/issues.md +0 -30
- package/WS__mia-code__260214__IAIP_PDE.code-workspace +0 -29
- package/WS__mia-code__src332__260122.code-workspace +0 -23
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/checkpoints/index.md +0 -6
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/events.jsonl +0 -213
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/plan.md +0 -243
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/workspace.yaml +0 -5
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
> ## Documentation Index
|
|
2
|
+
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
|
|
3
|
+
> Use this file to discover all available pages before exploring further.
|
|
4
|
+
|
|
5
|
+
# Short-term memory
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Memory is a system that remembers information about previous interactions. For AI agents, memory is crucial because it lets them remember previous interactions, learn from feedback, and adapt to user preferences. As agents tackle more complex tasks with numerous user interactions, this capability becomes essential for both efficiency and user satisfaction.
|
|
10
|
+
|
|
11
|
+
Short term memory lets your application remember previous interactions within a single thread or conversation.
|
|
12
|
+
|
|
13
|
+
<Note>
|
|
14
|
+
A thread organizes multiple interactions in a session, similar to the way email groups messages in a single conversation.
|
|
15
|
+
</Note>
|
|
16
|
+
|
|
17
|
+
Conversation history is the most common form of short-term memory. Long conversations pose a challenge to today's LLMs; a full history may not fit inside an LLM's context window, resulting in an context loss or errors.
|
|
18
|
+
|
|
19
|
+
Even if your model supports the full context length, most LLMs still perform poorly over long contexts. They get "distracted" by stale or off-topic content, all while suffering from slower response times and higher costs.
|
|
20
|
+
|
|
21
|
+
Chat models accept context using [messages](/oss/python/langchain/messages), which include instructions (a system message) and inputs (human messages). In chat applications, messages alternate between human inputs and model responses, resulting in a list of messages that grows longer over time. Because context windows are limited, many applications can benefit from using techniques to remove or "forget" stale information.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
To add short-term memory (thread-level persistence) to an agent, you need to specify a `checkpointer` when creating an agent.
|
|
26
|
+
|
|
27
|
+
<Info>
|
|
28
|
+
LangChain's agent manages short-term memory as a part of your agent's state.
|
|
29
|
+
|
|
30
|
+
By storing these in the graph's state, the agent can access the full context for a given conversation while maintaining separation between different threads.
|
|
31
|
+
|
|
32
|
+
State is persisted to a database (or memory) using a checkpointer so the thread can be resumed at any time.
|
|
33
|
+
|
|
34
|
+
Short-term memory updates when the agent is invoked or a step (like a tool call) is completed, and the state is read at the start of each step.
|
|
35
|
+
</Info>
|
|
36
|
+
|
|
37
|
+
```python theme={null}
|
|
38
|
+
from langchain.agents import create_agent
|
|
39
|
+
from langgraph.checkpoint.memory import InMemorySaver # [!code highlight]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
agent = create_agent(
|
|
43
|
+
"gpt-5",
|
|
44
|
+
tools=[get_user_info],
|
|
45
|
+
checkpointer=InMemorySaver(), # [!code highlight]
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
agent.invoke(
|
|
49
|
+
{"messages": [{"role": "user", "content": "Hi! My name is Bob."}]},
|
|
50
|
+
{"configurable": {"thread_id": "1"}}, # [!code highlight]
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### In production
|
|
55
|
+
|
|
56
|
+
In production, use a checkpointer backed by a database:
|
|
57
|
+
|
|
58
|
+
```shell theme={null}
|
|
59
|
+
pip install langgraph-checkpoint-postgres
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```python theme={null}
|
|
63
|
+
from langchain.agents import create_agent
|
|
64
|
+
|
|
65
|
+
from langgraph.checkpoint.postgres import PostgresSaver # [!code highlight]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
DB_URI = "postgresql://postgres:postgres@localhost:5442/postgres?sslmode=disable"
|
|
69
|
+
with PostgresSaver.from_conn_string(DB_URI) as checkpointer:
|
|
70
|
+
checkpointer.setup() # auto create tables in PostgresSql
|
|
71
|
+
agent = create_agent(
|
|
72
|
+
"gpt-5",
|
|
73
|
+
tools=[get_user_info],
|
|
74
|
+
checkpointer=checkpointer, # [!code highlight]
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
<Note>
|
|
79
|
+
For more checkpointer options including SQLite, Postgres, and Azure Cosmos DB, see the [list of checkpointer libraries](/oss/python/langgraph/persistence#checkpointer-libraries) in the Persistence documentation.
|
|
80
|
+
</Note>
|
|
81
|
+
|
|
82
|
+
## Customizing agent memory
|
|
83
|
+
|
|
84
|
+
By default, agents use [`AgentState`](https://reference.langchain.com/python/langchain/agents/#langchain.agents.AgentState) to manage short term memory, specifically the conversation history via a `messages` key.
|
|
85
|
+
|
|
86
|
+
You can extend [`AgentState`](https://reference.langchain.com/python/langchain/agents/#langchain.agents.AgentState) to add additional fields. Custom state schemas are passed to [`create_agent`](https://reference.langchain.com/python/langchain/agents/#langchain.agents.create_agent) using the [`state_schema`](https://reference.langchain.com/python/langchain/middleware/#langchain.agents.middleware.AgentMiddleware.state_schema) parameter.
|
|
87
|
+
|
|
88
|
+
```python theme={null}
|
|
89
|
+
from langchain.agents import create_agent, AgentState
|
|
90
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class CustomAgentState(AgentState): # [!code highlight]
|
|
94
|
+
user_id: str # [!code highlight]
|
|
95
|
+
preferences: dict # [!code highlight]
|
|
96
|
+
|
|
97
|
+
agent = create_agent(
|
|
98
|
+
"gpt-5",
|
|
99
|
+
tools=[get_user_info],
|
|
100
|
+
state_schema=CustomAgentState, # [!code highlight]
|
|
101
|
+
checkpointer=InMemorySaver(),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Custom state can be passed in invoke
|
|
105
|
+
result = agent.invoke(
|
|
106
|
+
{
|
|
107
|
+
"messages": [{"role": "user", "content": "Hello"}],
|
|
108
|
+
"user_id": "user_123", # [!code highlight]
|
|
109
|
+
"preferences": {"theme": "dark"} # [!code highlight]
|
|
110
|
+
},
|
|
111
|
+
{"configurable": {"thread_id": "1"}})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Common patterns
|
|
115
|
+
|
|
116
|
+
With [short-term memory](#add-short-term-memory) enabled, long conversations can exceed the LLM's context window. Common solutions are:
|
|
117
|
+
|
|
118
|
+
<CardGroup cols={2}>
|
|
119
|
+
<Card title="Trim messages" icon="scissors" href="#trim-messages" arrow>
|
|
120
|
+
Remove first or last N messages (before calling LLM)
|
|
121
|
+
</Card>
|
|
122
|
+
|
|
123
|
+
<Card title="Delete messages" icon="trash" href="#delete-messages" arrow>
|
|
124
|
+
Delete messages from LangGraph state permanently
|
|
125
|
+
</Card>
|
|
126
|
+
|
|
127
|
+
<Card title="Summarize messages" icon="layer-group" href="#summarize-messages" arrow>
|
|
128
|
+
Summarize earlier messages in the history and replace them with a summary
|
|
129
|
+
</Card>
|
|
130
|
+
|
|
131
|
+
<Card title="Custom strategies" icon="gears">
|
|
132
|
+
Custom strategies (e.g., message filtering, etc.)
|
|
133
|
+
</Card>
|
|
134
|
+
</CardGroup>
|
|
135
|
+
|
|
136
|
+
This allows the agent to keep track of the conversation without exceeding the LLM's context window.
|
|
137
|
+
|
|
138
|
+
### Trim messages
|
|
139
|
+
|
|
140
|
+
Most LLMs have a maximum supported context window (denominated in tokens).
|
|
141
|
+
|
|
142
|
+
One way to decide when to truncate messages is to count the tokens in the message history and truncate whenever it approaches that limit. If you're using LangChain, you can use the trim messages utility and specify the number of tokens to keep from the list, as well as the `strategy` (e.g., keep the last `max_tokens`) to use for handling the boundary.
|
|
143
|
+
|
|
144
|
+
To trim message history in an agent, use the [`@before_model`](https://reference.langchain.com/python/langchain/middleware/#langchain.agents.middleware.before_model) middleware decorator:
|
|
145
|
+
|
|
146
|
+
```python theme={null}
|
|
147
|
+
from langchain.messages import RemoveMessage
|
|
148
|
+
from langgraph.graph.message import REMOVE_ALL_MESSAGES
|
|
149
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
150
|
+
from langchain.agents import create_agent, AgentState
|
|
151
|
+
from langchain.agents.middleware import before_model
|
|
152
|
+
from langgraph.runtime import Runtime
|
|
153
|
+
from langchain_core.runnables import RunnableConfig
|
|
154
|
+
from typing import Any
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@before_model
|
|
158
|
+
def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:
|
|
159
|
+
"""Keep only the last few messages to fit context window."""
|
|
160
|
+
messages = state["messages"]
|
|
161
|
+
|
|
162
|
+
if len(messages) <= 3:
|
|
163
|
+
return None # No changes needed
|
|
164
|
+
|
|
165
|
+
first_msg = messages[0]
|
|
166
|
+
recent_messages = messages[-3:] if len(messages) % 2 == 0 else messages[-4:]
|
|
167
|
+
new_messages = [first_msg] + recent_messages
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
"messages": [
|
|
171
|
+
RemoveMessage(id=REMOVE_ALL_MESSAGES),
|
|
172
|
+
*new_messages
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
agent = create_agent(
|
|
177
|
+
your_model_here,
|
|
178
|
+
tools=your_tools_here,
|
|
179
|
+
middleware=[trim_messages],
|
|
180
|
+
checkpointer=InMemorySaver(),
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
config: RunnableConfig = {"configurable": {"thread_id": "1"}}
|
|
184
|
+
|
|
185
|
+
agent.invoke({"messages": "hi, my name is bob"}, config)
|
|
186
|
+
agent.invoke({"messages": "write a short poem about cats"}, config)
|
|
187
|
+
agent.invoke({"messages": "now do the same but for dogs"}, config)
|
|
188
|
+
final_response = agent.invoke({"messages": "what's my name?"}, config)
|
|
189
|
+
|
|
190
|
+
final_response["messages"][-1].pretty_print()
|
|
191
|
+
"""
|
|
192
|
+
================================== Ai Message ==================================
|
|
193
|
+
|
|
194
|
+
Your name is Bob. You told me that earlier.
|
|
195
|
+
If you'd like me to call you a nickname or use a different name, just say the word.
|
|
196
|
+
"""
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Delete messages
|
|
200
|
+
|
|
201
|
+
You can delete messages from the graph state to manage the message history.
|
|
202
|
+
|
|
203
|
+
This is useful when you want to remove specific messages or clear the entire message history.
|
|
204
|
+
|
|
205
|
+
To delete messages from the graph state, you can use the `RemoveMessage`.
|
|
206
|
+
|
|
207
|
+
For `RemoveMessage` to work, you need to use a state key with [`add_messages`](https://reference.langchain.com/python/langgraph/graphs/#langgraph.graph.message.add_messages) [reducer](/oss/python/langgraph/graph-api#reducers).
|
|
208
|
+
|
|
209
|
+
The default [`AgentState`](https://reference.langchain.com/python/langchain/agents/#langchain.agents.AgentState) provides this.
|
|
210
|
+
|
|
211
|
+
To remove specific messages:
|
|
212
|
+
|
|
213
|
+
```python theme={null}
|
|
214
|
+
from langchain.messages import RemoveMessage # [!code highlight]
|
|
215
|
+
|
|
216
|
+
def delete_messages(state):
|
|
217
|
+
messages = state["messages"]
|
|
218
|
+
if len(messages) > 2:
|
|
219
|
+
# remove the earliest two messages
|
|
220
|
+
return {"messages": [RemoveMessage(id=m.id) for m in messages[:2]]} # [!code highlight]
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
To remove **all** messages:
|
|
224
|
+
|
|
225
|
+
```python theme={null}
|
|
226
|
+
from langgraph.graph.message import REMOVE_ALL_MESSAGES # [!code highlight]
|
|
227
|
+
|
|
228
|
+
def delete_messages(state):
|
|
229
|
+
return {"messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES)]} # [!code highlight]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
<Warning>
|
|
233
|
+
When deleting messages, **make sure** that the resulting message history is valid. Check the limitations of the LLM provider you're using. For example:
|
|
234
|
+
|
|
235
|
+
* Some providers expect message history to start with a `user` message
|
|
236
|
+
* Most providers require `assistant` messages with tool calls to be followed by corresponding `tool` result messages.
|
|
237
|
+
</Warning>
|
|
238
|
+
|
|
239
|
+
```python theme={null}
|
|
240
|
+
from langchain.messages import RemoveMessage
|
|
241
|
+
from langchain.agents import create_agent, AgentState
|
|
242
|
+
from langchain.agents.middleware import after_model
|
|
243
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
244
|
+
from langgraph.runtime import Runtime
|
|
245
|
+
from langchain_core.runnables import RunnableConfig
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@after_model
|
|
249
|
+
def delete_old_messages(state: AgentState, runtime: Runtime) -> dict | None:
|
|
250
|
+
"""Remove old messages to keep conversation manageable."""
|
|
251
|
+
messages = state["messages"]
|
|
252
|
+
if len(messages) > 2:
|
|
253
|
+
# remove the earliest two messages
|
|
254
|
+
return {"messages": [RemoveMessage(id=m.id) for m in messages[:2]]}
|
|
255
|
+
return None
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
agent = create_agent(
|
|
259
|
+
"gpt-5-nano",
|
|
260
|
+
tools=[],
|
|
261
|
+
system_prompt="Please be concise and to the point.",
|
|
262
|
+
middleware=[delete_old_messages],
|
|
263
|
+
checkpointer=InMemorySaver(),
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
config: RunnableConfig = {"configurable": {"thread_id": "1"}}
|
|
267
|
+
|
|
268
|
+
for event in agent.stream(
|
|
269
|
+
{"messages": [{"role": "user", "content": "hi! I'm bob"}]},
|
|
270
|
+
config,
|
|
271
|
+
stream_mode="values",
|
|
272
|
+
):
|
|
273
|
+
print([(message.type, message.content) for message in event["messages"]])
|
|
274
|
+
|
|
275
|
+
for event in agent.stream(
|
|
276
|
+
{"messages": [{"role": "user", "content": "what's my name?"}]},
|
|
277
|
+
config,
|
|
278
|
+
stream_mode="values",
|
|
279
|
+
):
|
|
280
|
+
print([(message.type, message.content) for message in event["messages"]])
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
[('human', "hi! I'm bob")]
|
|
285
|
+
[('human', "hi! I'm bob"), ('ai', 'Hi Bob! Nice to meet you. How can I help you today? I can answer questions, brainstorm ideas, draft text, explain things, or help with code.')]
|
|
286
|
+
[('human', "hi! I'm bob"), ('ai', 'Hi Bob! Nice to meet you. How can I help you today? I can answer questions, brainstorm ideas, draft text, explain things, or help with code.'), ('human', "what's my name?")]
|
|
287
|
+
[('human', "hi! I'm bob"), ('ai', 'Hi Bob! Nice to meet you. How can I help you today? I can answer questions, brainstorm ideas, draft text, explain things, or help with code.'), ('human', "what's my name?"), ('ai', 'Your name is Bob. How can I help you today, Bob?')]
|
|
288
|
+
[('human', "what's my name?"), ('ai', 'Your name is Bob. How can I help you today, Bob?')]
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Summarize messages
|
|
292
|
+
|
|
293
|
+
The problem with trimming or removing messages, as shown above, is that you may lose information from culling of the message queue.
|
|
294
|
+
Because of this, some applications benefit from a more sophisticated approach of summarizing the message history using a chat model.
|
|
295
|
+
|
|
296
|
+
<img src="https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=c8ed3facdccd4ef5c7e52902c72ba938" alt="Summary" data-og-width="609" width="609" data-og-height="242" height="242" data-path="oss/images/summary.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=280&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=4208b9b0cc9f459f3dc4e5219918471b 280w, https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=560&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=7acb77c081545f57042368f4e9d0c8cb 560w, https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=840&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=2fcfdb0c481d2e1d361e76db763a41e5 840w, https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=1100&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=4abdac693a562788aa0db8681bef8ea7 1100w, https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=1650&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=40acfefa91dcb11b247a6e4a7705f22b 1650w, https://mintcdn.com/langchain-5e9cc07a/ybiAaBfoBvFquMDz/oss/images/summary.png?w=2500&fit=max&auto=format&n=ybiAaBfoBvFquMDz&q=85&s=8d765aaf7551e8b0fc2720de7d2ac2a8 2500w" />
|
|
297
|
+
|
|
298
|
+
To summarize message history in an agent, use the built-in [`SummarizationMiddleware`](/oss/python/langchain/middleware#summarization):
|
|
299
|
+
|
|
300
|
+
```python theme={null}
|
|
301
|
+
from langchain.agents import create_agent
|
|
302
|
+
from langchain.agents.middleware import SummarizationMiddleware
|
|
303
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
304
|
+
from langchain_core.runnables import RunnableConfig
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
checkpointer = InMemorySaver()
|
|
308
|
+
|
|
309
|
+
agent = create_agent(
|
|
310
|
+
model="gpt-4.1",
|
|
311
|
+
tools=[],
|
|
312
|
+
middleware=[
|
|
313
|
+
SummarizationMiddleware(
|
|
314
|
+
model="gpt-4.1-mini",
|
|
315
|
+
trigger=("tokens", 4000),
|
|
316
|
+
keep=("messages", 20)
|
|
317
|
+
)
|
|
318
|
+
],
|
|
319
|
+
checkpointer=checkpointer,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
config: RunnableConfig = {"configurable": {"thread_id": "1"}}
|
|
323
|
+
agent.invoke({"messages": "hi, my name is bob"}, config)
|
|
324
|
+
agent.invoke({"messages": "write a short poem about cats"}, config)
|
|
325
|
+
agent.invoke({"messages": "now do the same but for dogs"}, config)
|
|
326
|
+
final_response = agent.invoke({"messages": "what's my name?"}, config)
|
|
327
|
+
|
|
328
|
+
final_response["messages"][-1].pretty_print()
|
|
329
|
+
"""
|
|
330
|
+
================================== Ai Message ==================================
|
|
331
|
+
|
|
332
|
+
Your name is Bob!
|
|
333
|
+
"""
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
See [`SummarizationMiddleware`](/oss/python/langchain/middleware#summarization) for more configuration options.
|
|
337
|
+
|
|
338
|
+
## Access memory
|
|
339
|
+
|
|
340
|
+
You can access and modify the short-term memory (state) of an agent in several ways:
|
|
341
|
+
|
|
342
|
+
### Tools
|
|
343
|
+
|
|
344
|
+
#### Read short-term memory in a tool
|
|
345
|
+
|
|
346
|
+
Access short term memory (state) in a tool using the `runtime` parameter (typed as `ToolRuntime`).
|
|
347
|
+
|
|
348
|
+
The `runtime` parameter is hidden from the tool signature (so the model doesn't see it), but the tool can access the state through it.
|
|
349
|
+
|
|
350
|
+
```python theme={null}
|
|
351
|
+
from langchain.agents import create_agent, AgentState
|
|
352
|
+
from langchain.tools import tool, ToolRuntime
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
class CustomState(AgentState):
|
|
356
|
+
user_id: str
|
|
357
|
+
|
|
358
|
+
@tool
|
|
359
|
+
def get_user_info(
|
|
360
|
+
runtime: ToolRuntime
|
|
361
|
+
) -> str:
|
|
362
|
+
"""Look up user info."""
|
|
363
|
+
user_id = runtime.state["user_id"]
|
|
364
|
+
return "User is John Smith" if user_id == "user_123" else "Unknown user"
|
|
365
|
+
|
|
366
|
+
agent = create_agent(
|
|
367
|
+
model="gpt-5-nano",
|
|
368
|
+
tools=[get_user_info],
|
|
369
|
+
state_schema=CustomState,
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
result = agent.invoke({
|
|
373
|
+
"messages": "look up user information",
|
|
374
|
+
"user_id": "user_123"
|
|
375
|
+
})
|
|
376
|
+
print(result["messages"][-1].content)
|
|
377
|
+
# > User is John Smith.
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
#### Write short-term memory from tools
|
|
381
|
+
|
|
382
|
+
To modify the agent's short-term memory (state) during execution, you can return state updates directly from the tools.
|
|
383
|
+
|
|
384
|
+
This is useful for persisting intermediate results or making information accessible to subsequent tools or prompts.
|
|
385
|
+
|
|
386
|
+
```python theme={null}
|
|
387
|
+
from langchain.tools import tool, ToolRuntime
|
|
388
|
+
from langchain_core.runnables import RunnableConfig
|
|
389
|
+
from langchain.messages import ToolMessage
|
|
390
|
+
from langchain.agents import create_agent, AgentState
|
|
391
|
+
from langgraph.types import Command
|
|
392
|
+
from pydantic import BaseModel
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
class CustomState(AgentState): # [!code highlight]
|
|
396
|
+
user_name: str
|
|
397
|
+
|
|
398
|
+
class CustomContext(BaseModel):
|
|
399
|
+
user_id: str
|
|
400
|
+
|
|
401
|
+
@tool
|
|
402
|
+
def update_user_info(
|
|
403
|
+
runtime: ToolRuntime[CustomContext, CustomState],
|
|
404
|
+
) -> Command:
|
|
405
|
+
"""Look up and update user info."""
|
|
406
|
+
user_id = runtime.context.user_id
|
|
407
|
+
name = "John Smith" if user_id == "user_123" else "Unknown user"
|
|
408
|
+
return Command(update={ # [!code highlight]
|
|
409
|
+
"user_name": name,
|
|
410
|
+
# update the message history
|
|
411
|
+
"messages": [
|
|
412
|
+
ToolMessage(
|
|
413
|
+
"Successfully looked up user information",
|
|
414
|
+
tool_call_id=runtime.tool_call_id
|
|
415
|
+
)
|
|
416
|
+
]
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
@tool
|
|
420
|
+
def greet(
|
|
421
|
+
runtime: ToolRuntime[CustomContext, CustomState]
|
|
422
|
+
) -> str | Command:
|
|
423
|
+
"""Use this to greet the user once you found their info."""
|
|
424
|
+
user_name = runtime.state.get("user_name", None)
|
|
425
|
+
if user_name is None:
|
|
426
|
+
return Command(update={
|
|
427
|
+
"messages": [
|
|
428
|
+
ToolMessage(
|
|
429
|
+
"Please call the 'update_user_info' tool it will get and update the user's name.",
|
|
430
|
+
tool_call_id=runtime.tool_call_id
|
|
431
|
+
)
|
|
432
|
+
]
|
|
433
|
+
})
|
|
434
|
+
return f"Hello {user_name}!"
|
|
435
|
+
|
|
436
|
+
agent = create_agent(
|
|
437
|
+
model="gpt-5-nano",
|
|
438
|
+
tools=[update_user_info, greet],
|
|
439
|
+
state_schema=CustomState, # [!code highlight]
|
|
440
|
+
context_schema=CustomContext,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
agent.invoke(
|
|
444
|
+
{"messages": [{"role": "user", "content": "greet the user"}]},
|
|
445
|
+
context=CustomContext(user_id="user_123"),
|
|
446
|
+
)
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Prompt
|
|
450
|
+
|
|
451
|
+
Access short term memory (state) in middleware to create dynamic prompts based on conversation history or custom state fields.
|
|
452
|
+
|
|
453
|
+
```python theme={null}
|
|
454
|
+
from langchain.agents import create_agent
|
|
455
|
+
from typing import TypedDict
|
|
456
|
+
from langchain.agents.middleware import dynamic_prompt, ModelRequest
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
class CustomContext(TypedDict):
|
|
460
|
+
user_name: str
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def get_weather(city: str) -> str:
|
|
464
|
+
"""Get the weather in a city."""
|
|
465
|
+
return f"The weather in {city} is always sunny!"
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
@dynamic_prompt
|
|
469
|
+
def dynamic_system_prompt(request: ModelRequest) -> str:
|
|
470
|
+
user_name = request.runtime.context["user_name"]
|
|
471
|
+
system_prompt = f"You are a helpful assistant. Address the user as {user_name}."
|
|
472
|
+
return system_prompt
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
agent = create_agent(
|
|
476
|
+
model="gpt-5-nano",
|
|
477
|
+
tools=[get_weather],
|
|
478
|
+
middleware=[dynamic_system_prompt],
|
|
479
|
+
context_schema=CustomContext,
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
result = agent.invoke(
|
|
483
|
+
{"messages": [{"role": "user", "content": "What is the weather in SF?"}]},
|
|
484
|
+
context=CustomContext(user_name="John Smith"),
|
|
485
|
+
)
|
|
486
|
+
for msg in result["messages"]:
|
|
487
|
+
msg.pretty_print()
|
|
488
|
+
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
```shell title="Output" theme={null}
|
|
492
|
+
================================ Human Message =================================
|
|
493
|
+
|
|
494
|
+
What is the weather in SF?
|
|
495
|
+
================================== Ai Message ==================================
|
|
496
|
+
Tool Calls:
|
|
497
|
+
get_weather (call_WFQlOGn4b2yoJrv7cih342FG)
|
|
498
|
+
Call ID: call_WFQlOGn4b2yoJrv7cih342FG
|
|
499
|
+
Args:
|
|
500
|
+
city: San Francisco
|
|
501
|
+
================================= Tool Message =================================
|
|
502
|
+
Name: get_weather
|
|
503
|
+
|
|
504
|
+
The weather in San Francisco is always sunny!
|
|
505
|
+
================================== Ai Message ==================================
|
|
506
|
+
|
|
507
|
+
Hi John Smith, the weather in San Francisco is always sunny!
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Before model
|
|
511
|
+
|
|
512
|
+
Access short term memory (state) in [`@before_model`](https://reference.langchain.com/python/langchain/middleware/#langchain.agents.middleware.before_model) middleware to process messages before model calls.
|
|
513
|
+
|
|
514
|
+
```mermaid theme={null}
|
|
515
|
+
%%{
|
|
516
|
+
init: {
|
|
517
|
+
"fontFamily": "monospace",
|
|
518
|
+
"flowchart": {
|
|
519
|
+
"curve": "basis"
|
|
520
|
+
},
|
|
521
|
+
"themeVariables": {"edgeLabelBackground": "transparent"}
|
|
522
|
+
}
|
|
523
|
+
}%%
|
|
524
|
+
graph TD
|
|
525
|
+
S(["\_\_start\_\_"])
|
|
526
|
+
PRE(before_model)
|
|
527
|
+
MODEL(model)
|
|
528
|
+
TOOLS(tools)
|
|
529
|
+
END(["\_\_end\_\_"])
|
|
530
|
+
S --> PRE
|
|
531
|
+
PRE --> MODEL
|
|
532
|
+
MODEL -.-> TOOLS
|
|
533
|
+
MODEL -.-> END
|
|
534
|
+
TOOLS --> PRE
|
|
535
|
+
classDef blueHighlight fill:#0a1c25,stroke:#0a455f,color:#bae6fd;
|
|
536
|
+
class S blueHighlight;
|
|
537
|
+
class END blueHighlight;
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
```python theme={null}
|
|
541
|
+
from langchain.messages import RemoveMessage
|
|
542
|
+
from langgraph.graph.message import REMOVE_ALL_MESSAGES
|
|
543
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
544
|
+
from langchain.agents import create_agent, AgentState
|
|
545
|
+
from langchain.agents.middleware import before_model
|
|
546
|
+
from langchain_core.runnables import RunnableConfig
|
|
547
|
+
from langgraph.runtime import Runtime
|
|
548
|
+
from typing import Any
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
@before_model
|
|
552
|
+
def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None:
|
|
553
|
+
"""Keep only the last few messages to fit context window."""
|
|
554
|
+
messages = state["messages"]
|
|
555
|
+
|
|
556
|
+
if len(messages) <= 3:
|
|
557
|
+
return None # No changes needed
|
|
558
|
+
|
|
559
|
+
first_msg = messages[0]
|
|
560
|
+
recent_messages = messages[-3:] if len(messages) % 2 == 0 else messages[-4:]
|
|
561
|
+
new_messages = [first_msg] + recent_messages
|
|
562
|
+
|
|
563
|
+
return {
|
|
564
|
+
"messages": [
|
|
565
|
+
RemoveMessage(id=REMOVE_ALL_MESSAGES),
|
|
566
|
+
*new_messages
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
agent = create_agent(
|
|
572
|
+
"gpt-5-nano",
|
|
573
|
+
tools=[],
|
|
574
|
+
middleware=[trim_messages],
|
|
575
|
+
checkpointer=InMemorySaver()
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
config: RunnableConfig = {"configurable": {"thread_id": "1"}}
|
|
579
|
+
|
|
580
|
+
agent.invoke({"messages": "hi, my name is bob"}, config)
|
|
581
|
+
agent.invoke({"messages": "write a short poem about cats"}, config)
|
|
582
|
+
agent.invoke({"messages": "now do the same but for dogs"}, config)
|
|
583
|
+
final_response = agent.invoke({"messages": "what's my name?"}, config)
|
|
584
|
+
|
|
585
|
+
final_response["messages"][-1].pretty_print()
|
|
586
|
+
"""
|
|
587
|
+
================================== Ai Message ==================================
|
|
588
|
+
|
|
589
|
+
Your name is Bob. You told me that earlier.
|
|
590
|
+
If you'd like me to call you a nickname or use a different name, just say the word.
|
|
591
|
+
"""
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### After model
|
|
595
|
+
|
|
596
|
+
Access short term memory (state) in [`@after_model`](https://reference.langchain.com/python/langchain/middleware/#langchain.agents.middleware.after_model) middleware to process messages after model calls.
|
|
597
|
+
|
|
598
|
+
```mermaid theme={null}
|
|
599
|
+
%%{
|
|
600
|
+
init: {
|
|
601
|
+
"fontFamily": "monospace",
|
|
602
|
+
"flowchart": {
|
|
603
|
+
"curve": "basis"
|
|
604
|
+
},
|
|
605
|
+
"themeVariables": {"edgeLabelBackground": "transparent"}
|
|
606
|
+
}
|
|
607
|
+
}%%
|
|
608
|
+
graph TD
|
|
609
|
+
S(["\_\_start\_\_"])
|
|
610
|
+
MODEL(model)
|
|
611
|
+
POST(after_model)
|
|
612
|
+
TOOLS(tools)
|
|
613
|
+
END(["\_\_end\_\_"])
|
|
614
|
+
S --> MODEL
|
|
615
|
+
MODEL --> POST
|
|
616
|
+
POST -.-> END
|
|
617
|
+
POST -.-> TOOLS
|
|
618
|
+
TOOLS --> MODEL
|
|
619
|
+
classDef blueHighlight fill:#0a1c25,stroke:#0a455f,color:#bae6fd;
|
|
620
|
+
class S blueHighlight;
|
|
621
|
+
class END blueHighlight;
|
|
622
|
+
class POST greenHighlight;
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
```python theme={null}
|
|
626
|
+
from langchain.messages import RemoveMessage
|
|
627
|
+
from langgraph.checkpoint.memory import InMemorySaver
|
|
628
|
+
from langchain.agents import create_agent, AgentState
|
|
629
|
+
from langchain.agents.middleware import after_model
|
|
630
|
+
from langgraph.runtime import Runtime
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
@after_model
|
|
634
|
+
def validate_response(state: AgentState, runtime: Runtime) -> dict | None:
|
|
635
|
+
"""Remove messages containing sensitive words."""
|
|
636
|
+
STOP_WORDS = ["password", "secret"]
|
|
637
|
+
last_message = state["messages"][-1]
|
|
638
|
+
if any(word in last_message.content for word in STOP_WORDS):
|
|
639
|
+
return {"messages": [RemoveMessage(id=last_message.id)]}
|
|
640
|
+
return None
|
|
641
|
+
|
|
642
|
+
agent = create_agent(
|
|
643
|
+
model="gpt-5-nano",
|
|
644
|
+
tools=[],
|
|
645
|
+
middleware=[validate_response],
|
|
646
|
+
checkpointer=InMemorySaver(),
|
|
647
|
+
)
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
***
|
|
651
|
+
|
|
652
|
+
<Callout icon="pen-to-square" iconType="regular">
|
|
653
|
+
[Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/short-term-memory.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
|
|
654
|
+
</Callout>
|
|
655
|
+
|
|
656
|
+
<Tip icon="terminal" iconType="regular">
|
|
657
|
+
[Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
|
|
658
|
+
</Tip>
|