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.
Files changed (410) hide show
  1. package/.miette/260321.md +1 -0
  2. package/.miette/260323.md +9 -0
  3. package/.miette/260331.md +2 -0
  4. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--d3417f2c-df12-4f0f-8a1b-d88e7968f822/d3417f2c-df12-4f0f-8a1b-d88e7968f822.md +63 -0
  5. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--e6c3fc5d-4a70-4523-ba7d-a3250da4c235/e6c3fc5d-4a70-4523-ba7d-a3250da4c235.md +72 -0
  6. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--efeb00a2-b17a-4d32-b1f0-b90c37a8d24e/efeb00a2-b17a-4d32-b1f0-b90c37a8d24e.md +62 -0
  7. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.json +302 -0
  8. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.md +149 -0
  9. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/AGENTS.md +31 -0
  10. package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/meta-decomposition-3-children.md +67 -0
  11. package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/61f9dd4d-7aa6-45e6-a58b-e480b1aa6737--from-mia-openclaw-workspace.md +125 -0
  12. package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/STATUS.md +1 -0
  13. package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.json +177 -0
  14. package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.md +77 -0
  15. package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.json +222 -0
  16. package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.md +99 -0
  17. package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.json +111 -0
  18. package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.md +67 -0
  19. package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.json +349 -0
  20. package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.md +147 -0
  21. package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.json +118 -0
  22. package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.md +64 -0
  23. package/GUILLAUME.md +8 -0
  24. package/KINSHIP.md +9 -0
  25. package/MIA_CODE_ARCHITECTURE_REPORT.md +718 -0
  26. package/contextual_research/260119-MIA-CODE--98090899-8aff-4e11-9dc3-8b99466d1.md +1101 -0
  27. package/contextual_research/MIA.md +38 -0
  28. package/contextual_research/MIAWAPASCONE.md +59 -0
  29. package/contextual_research/MIETTE.md +38 -0
  30. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2504.00218v2.pdf +7483 -12
  31. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2505.00212v3.pdf +0 -0
  32. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/CONTENT.md +1014 -0
  33. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/DESIGN.gemini.md +242 -0
  34. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/INDEX.md +45 -0
  35. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.md +2025 -0
  36. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.pdf +7483 -12
  37. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.md +1755 -0
  38. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.pdf +0 -0
  39. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_12_decomposed_prompting.pdf +0 -0
  40. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_19_hugginggpt_planning.pdf +0 -0
  41. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.md +766 -0
  42. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.pdf +3431 -4
  43. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.md +260 -0
  44. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.pdf +0 -0
  45. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.md +558 -0
  46. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.pdf +0 -0
  47. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_34_hierarchical_multi_agent.pdf +0 -0
  48. package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_5_open_intent_extraction.pdf +0 -0
  49. package/contextual_research/PODCAST.md +109 -0
  50. package/contextual_research/langchain-principles-roadmap.md +157 -0
  51. package/contextual_research/persona-to-narrative-character-inquiry_260201.md +50 -0
  52. package/dist/cli.js +35 -11
  53. package/dist/geminiHeadless.js +8 -2
  54. package/dist/index.js +2 -1
  55. package/dist/mcp/miaco-server.js +10 -1
  56. package/dist/mcp/miatel-server.js +10 -1
  57. package/dist/mcp/miawa-server.js +10 -1
  58. package/dist/mcp/utils.d.ts +6 -1
  59. package/dist/mcp/utils.js +24 -3
  60. package/dist/sessionStore.d.ts +8 -2
  61. package/dist/sessionStore.js +39 -3
  62. package/dist/types.d.ts +1 -0
  63. package/miaco/README.md +124 -0
  64. package/miaco/dist/commands/chart.d.ts +6 -0
  65. package/miaco/dist/commands/chart.d.ts.map +1 -0
  66. package/miaco/dist/commands/chart.js +222 -0
  67. package/miaco/dist/commands/chart.js.map +1 -0
  68. package/miaco/dist/commands/decompose.d.ts +6 -0
  69. package/miaco/dist/commands/decompose.d.ts.map +1 -0
  70. package/miaco/dist/commands/decompose.js +98 -0
  71. package/miaco/dist/commands/decompose.js.map +1 -0
  72. package/miaco/dist/commands/schema.d.ts +6 -0
  73. package/miaco/dist/commands/schema.d.ts.map +1 -0
  74. package/miaco/dist/commands/schema.js +66 -0
  75. package/miaco/dist/commands/schema.js.map +1 -0
  76. package/miaco/dist/commands/stc.d.ts +11 -0
  77. package/miaco/dist/commands/stc.d.ts.map +1 -0
  78. package/miaco/dist/commands/stc.js +590 -0
  79. package/miaco/dist/commands/stc.js.map +1 -0
  80. package/miaco/dist/commands/trace.d.ts +6 -0
  81. package/miaco/dist/commands/trace.d.ts.map +1 -0
  82. package/miaco/dist/commands/trace.js +83 -0
  83. package/miaco/dist/commands/trace.js.map +1 -0
  84. package/miaco/dist/commands/validate.d.ts +6 -0
  85. package/miaco/dist/commands/validate.d.ts.map +1 -0
  86. package/miaco/dist/commands/validate.js +58 -0
  87. package/miaco/dist/commands/validate.js.map +1 -0
  88. package/miaco/dist/decompose.d.ts +93 -0
  89. package/miaco/dist/decompose.d.ts.map +1 -0
  90. package/miaco/dist/decompose.js +562 -0
  91. package/miaco/dist/decompose.js.map +1 -0
  92. package/miaco/dist/index.d.ts +18 -0
  93. package/miaco/dist/index.d.ts.map +1 -0
  94. package/miaco/dist/index.js +83 -0
  95. package/miaco/dist/index.js.map +1 -0
  96. package/miaco/dist/storage.d.ts +60 -0
  97. package/miaco/dist/storage.d.ts.map +1 -0
  98. package/miaco/dist/storage.js +100 -0
  99. package/miaco/dist/storage.js.map +1 -0
  100. package/miaco/package-lock.json +4103 -0
  101. package/miaco/package.json +40 -0
  102. package/miaco/tsconfig.json +18 -0
  103. package/miaco/version-patch-commit-and-publish.sh +1 -0
  104. package/miatel/MISSION_251231.md +3 -0
  105. package/miatel/README.md +107 -0
  106. package/miatel/dist/commands/analyze.d.ts +6 -0
  107. package/miatel/dist/commands/analyze.d.ts.map +1 -0
  108. package/miatel/dist/commands/analyze.js +100 -0
  109. package/miatel/dist/commands/analyze.js.map +1 -0
  110. package/miatel/dist/commands/arc.d.ts +6 -0
  111. package/miatel/dist/commands/arc.d.ts.map +1 -0
  112. package/miatel/dist/commands/arc.js +71 -0
  113. package/miatel/dist/commands/arc.js.map +1 -0
  114. package/miatel/dist/commands/beat.d.ts +6 -0
  115. package/miatel/dist/commands/beat.d.ts.map +1 -0
  116. package/miatel/dist/commands/beat.js +165 -0
  117. package/miatel/dist/commands/beat.js.map +1 -0
  118. package/miatel/dist/commands/theme.d.ts +6 -0
  119. package/miatel/dist/commands/theme.d.ts.map +1 -0
  120. package/miatel/dist/commands/theme.js +54 -0
  121. package/miatel/dist/commands/theme.js.map +1 -0
  122. package/miatel/dist/index.d.ts +18 -0
  123. package/miatel/dist/index.d.ts.map +1 -0
  124. package/miatel/dist/index.js +80 -0
  125. package/miatel/dist/index.js.map +1 -0
  126. package/miatel/dist/storage.d.ts +55 -0
  127. package/miatel/dist/storage.d.ts.map +1 -0
  128. package/miatel/dist/storage.js +100 -0
  129. package/miatel/dist/storage.js.map +1 -0
  130. package/miatel/package-lock.json +4103 -0
  131. package/miatel/package.json +35 -0
  132. package/miatel/src/commands/analyze.ts +109 -0
  133. package/miatel/src/commands/arc.ts +78 -0
  134. package/miatel/src/commands/beat.ts +176 -0
  135. package/miatel/src/commands/theme.ts +60 -0
  136. package/miatel/src/index.ts +94 -0
  137. package/miatel/src/storage.ts +156 -0
  138. package/miatel/tsconfig.json +18 -0
  139. package/miawa/MISSION_251231.md +144 -0
  140. package/miawa/README.md +133 -0
  141. package/miawa/dist/commands/beat.d.ts +6 -0
  142. package/miawa/dist/commands/beat.d.ts.map +1 -0
  143. package/miawa/dist/commands/beat.js +69 -0
  144. package/miawa/dist/commands/beat.js.map +1 -0
  145. package/miawa/dist/commands/ceremony.d.ts +6 -0
  146. package/miawa/dist/commands/ceremony.d.ts.map +1 -0
  147. package/miawa/dist/commands/ceremony.js +239 -0
  148. package/miawa/dist/commands/ceremony.js.map +1 -0
  149. package/miawa/dist/commands/circle.d.ts +6 -0
  150. package/miawa/dist/commands/circle.d.ts.map +1 -0
  151. package/miawa/dist/commands/circle.js +75 -0
  152. package/miawa/dist/commands/circle.js.map +1 -0
  153. package/miawa/dist/commands/eva.d.ts +6 -0
  154. package/miawa/dist/commands/eva.d.ts.map +1 -0
  155. package/miawa/dist/commands/eva.js +73 -0
  156. package/miawa/dist/commands/eva.js.map +1 -0
  157. package/miawa/dist/commands/wound.d.ts +6 -0
  158. package/miawa/dist/commands/wound.d.ts.map +1 -0
  159. package/miawa/dist/commands/wound.js +74 -0
  160. package/miawa/dist/commands/wound.js.map +1 -0
  161. package/miawa/dist/index.d.ts +19 -0
  162. package/miawa/dist/index.d.ts.map +1 -0
  163. package/miawa/dist/index.js +91 -0
  164. package/miawa/dist/index.js.map +1 -0
  165. package/miawa/dist/storage.d.ts +73 -0
  166. package/miawa/dist/storage.d.ts.map +1 -0
  167. package/miawa/dist/storage.js +100 -0
  168. package/miawa/dist/storage.js.map +1 -0
  169. package/miawa/package-lock.json +4103 -0
  170. package/miawa/package.json +36 -0
  171. package/miawa/src/commands/beat.ts +74 -0
  172. package/miawa/src/commands/ceremony.ts +256 -0
  173. package/miawa/src/commands/circle.ts +83 -0
  174. package/miawa/src/commands/eva.ts +84 -0
  175. package/miawa/src/commands/wound.ts +79 -0
  176. package/miawa/src/index.ts +108 -0
  177. package/miawa/src/storage.ts +179 -0
  178. package/miawa/tsconfig.json +18 -0
  179. package/package.json +7 -5
  180. package/references/acp/CLAUDE.md +7 -0
  181. package/references/acp/agent-plan.md +84 -0
  182. package/references/acp/clients.md +31 -0
  183. package/references/acp/extensibility.md +137 -0
  184. package/references/acp/initialization.md +225 -0
  185. package/references/acp/prompt-turn.md +321 -0
  186. package/references/acp/proxy-chains.md +562 -0
  187. package/references/acp/schema.md +3171 -0
  188. package/references/acp/session-list.md +334 -0
  189. package/references/acp/session-modes.md +170 -0
  190. package/references/acp/slash-commands.md +99 -0
  191. package/references/acp/terminals.md +281 -0
  192. package/references/acp/tool-calls.md +311 -0
  193. package/references/acp/typescript.md +29 -0
  194. package/references/claude/agent-teams.md +399 -0
  195. package/references/claude/chrome.md +231 -0
  196. package/references/claude/headless.md +158 -0
  197. package/references/claude/hooks-guide.md +708 -0
  198. package/references/claude/output-styles.md +112 -0
  199. package/references/claude/plugins.md +432 -0
  200. package/references/claude/skills.md +693 -0
  201. package/references/claude/sub-agents.md +816 -0
  202. package/references/copilot/acp/agents.md +32 -0
  203. package/references/copilot/acp/architecture.md +37 -0
  204. package/references/copilot/acp/clients.md +31 -0
  205. package/references/copilot/acp/introduction.md +42 -0
  206. package/references/copilot/acp/registry.md +339 -0
  207. package/references/copilot/acp-server.md +117 -0
  208. package/references/copilot/create-copilot-instructions.md +840 -0
  209. package/references/langchain/llms.txt +833 -0
  210. package/references/langchain/python/agents.md +677 -0
  211. package/references/langchain/python/context-engineering.md +1195 -0
  212. package/references/langchain/python/human-in-the-loop.md +326 -0
  213. package/references/langchain/python/long-term-memory.md +168 -0
  214. package/references/langchain/python/mcp.md +949 -0
  215. package/references/langchain/python/multi-agents/custom-workflow.md +187 -0
  216. package/references/langchain/python/multi-agents/handoffs.md +436 -0
  217. package/references/langchain/python/multi-agents/overview.md +295 -0
  218. package/references/langchain/python/multi-agents/router.md +150 -0
  219. package/references/langchain/python/multi-agents/skills.md +92 -0
  220. package/references/langchain/python/multi-agents/subagents.md +486 -0
  221. package/references/langchain/python/retrieval.md +320 -0
  222. package/references/langchain/python/runtime.md +141 -0
  223. package/references/langchain/python/short-term-memory.md +658 -0
  224. package/references/langchain/python/structured-output.md +712 -0
  225. package/references/langfuse/llms.txt +148 -0
  226. package/references/langgraph/javascript/llms.txt +275 -0
  227. package/references/skills/home.md +259 -0
  228. package/references/skills/integrate-skills.md +103 -0
  229. package/references/skills/specification.md +254 -0
  230. package/references/skills/what-are-skills.md +74 -0
  231. package/rispecs/README.md +164 -0
  232. package/rispecs/_sync_/miadi-code/SPEC.md +313 -0
  233. package/rispecs/_sync_/miadi-code/STATUS.md +177 -0
  234. package/rispecs/_sync_/miadi-code/dashboard/SPEC.md +465 -0
  235. package/rispecs/_sync_/miadi-code/dashboard/STATUS.md +212 -0
  236. package/rispecs/_sync_/miadi-code/multiline-input/SPEC.md +232 -0
  237. package/rispecs/_sync_/miadi-code/multiline-input/STATUS.md +108 -0
  238. package/rispecs/_sync_/miadi-code/pde/SPEC.md +253 -0
  239. package/rispecs/_sync_/miadi-code/pde/STATUS.md +56 -0
  240. package/rispecs/_sync_/miadi-code/stc/SPEC.md +397 -0
  241. package/rispecs/_sync_/miadi-code/stc/STATUS.md +70 -0
  242. package/rispecs/ava-langstack/inquiry-routing-upgrade.spec.md +119 -0
  243. package/rispecs/borrowed_from_opencode/001-client-server-architecture.rispec.md +98 -0
  244. package/rispecs/borrowed_from_opencode/002-event-bus-system.rispec.md +125 -0
  245. package/rispecs/borrowed_from_opencode/003-instance-state-pattern.rispec.md +136 -0
  246. package/rispecs/borrowed_from_opencode/004-namespace-module-pattern.rispec.md +151 -0
  247. package/rispecs/borrowed_from_opencode/005-zod-schema-validation.rispec.md +139 -0
  248. package/rispecs/borrowed_from_opencode/006-named-error-system.rispec.md +155 -0
  249. package/rispecs/borrowed_from_opencode/007-structured-logging.rispec.md +138 -0
  250. package/rispecs/borrowed_from_opencode/008-lazy-initialization.rispec.md +127 -0
  251. package/rispecs/borrowed_from_opencode/009-multi-agent-system.rispec.md +97 -0
  252. package/rispecs/borrowed_from_opencode/010-agent-definition-config.rispec.md +135 -0
  253. package/rispecs/borrowed_from_opencode/011-agent-permission-rulesets.rispec.md +151 -0
  254. package/rispecs/borrowed_from_opencode/012-agent-prompt-templates.rispec.md +141 -0
  255. package/rispecs/borrowed_from_opencode/013-agent-generation.rispec.md +142 -0
  256. package/rispecs/borrowed_from_opencode/014-plan-build-mode-toggle.rispec.md +155 -0
  257. package/rispecs/borrowed_from_opencode/015-subagent-task-delegation.rispec.md +146 -0
  258. package/rispecs/borrowed_from_opencode/016-agent-model-selection.rispec.md +151 -0
  259. package/rispecs/borrowed_from_opencode/017-compaction-agent.rispec.md +150 -0
  260. package/rispecs/borrowed_from_opencode/018-session-persistence.rispec.md +125 -0
  261. package/rispecs/borrowed_from_opencode/019-session-compaction.rispec.md +132 -0
  262. package/rispecs/borrowed_from_opencode/020-session-forking.rispec.md +134 -0
  263. package/rispecs/borrowed_from_opencode/021-session-revert-snapshot.rispec.md +135 -0
  264. package/rispecs/borrowed_from_opencode/022-session-sharing.rispec.md +165 -0
  265. package/rispecs/borrowed_from_opencode/023-session-summary-diffs.rispec.md +165 -0
  266. package/rispecs/borrowed_from_opencode/024-child-sessions.rispec.md +164 -0
  267. package/rispecs/borrowed_from_opencode/025-session-title-generation.rispec.md +162 -0
  268. package/rispecs/borrowed_from_opencode/026-message-parts-model.rispec.md +201 -0
  269. package/rispecs/borrowed_from_opencode/027-streaming-message-deltas.rispec.md +212 -0
  270. package/rispecs/borrowed_from_opencode/028-multi-provider-architecture.rispec.md +184 -0
  271. package/rispecs/borrowed_from_opencode/029-provider-authentication.rispec.md +225 -0
  272. package/rispecs/borrowed_from_opencode/030-model-registry.rispec.md +222 -0
  273. package/rispecs/borrowed_from_opencode/031-cost-tracking.rispec.md +243 -0
  274. package/rispecs/borrowed_from_opencode/032-provider-transform-pipeline.rispec.md +282 -0
  275. package/rispecs/borrowed_from_opencode/033-provider-sdk-abstraction.rispec.md +338 -0
  276. package/rispecs/borrowed_from_opencode/034-tool-registry.rispec.md +110 -0
  277. package/rispecs/borrowed_from_opencode/035-tool-context-injection.rispec.md +155 -0
  278. package/rispecs/borrowed_from_opencode/036-tool-output-truncation.rispec.md +138 -0
  279. package/rispecs/borrowed_from_opencode/037-batch-tool.rispec.md +129 -0
  280. package/rispecs/borrowed_from_opencode/038-multi-edit-tool.rispec.md +167 -0
  281. package/rispecs/borrowed_from_opencode/039-apply-patch-tool.rispec.md +161 -0
  282. package/rispecs/borrowed_from_opencode/040-code-search-tool.rispec.md +143 -0
  283. package/rispecs/borrowed_from_opencode/041-web-fetch-tool.rispec.md +131 -0
  284. package/rispecs/borrowed_from_opencode/042-web-search-tool.rispec.md +159 -0
  285. package/rispecs/borrowed_from_opencode/043-todo-tool.rispec.md +156 -0
  286. package/rispecs/borrowed_from_opencode/044-plan-mode-tool.rispec.md +139 -0
  287. package/rispecs/borrowed_from_opencode/045-task-tool.rispec.md +146 -0
  288. package/rispecs/borrowed_from_opencode/046-question-tool.rispec.md +170 -0
  289. package/rispecs/borrowed_from_opencode/047-external-directory-tool.rispec.md +166 -0
  290. package/rispecs/borrowed_from_opencode/048-file-read-write-tools.rispec.md +205 -0
  291. package/rispecs/borrowed_from_opencode/049-lsp-server-management.rispec.md +104 -0
  292. package/rispecs/borrowed_from_opencode/050-lsp-hover-completion.rispec.md +102 -0
  293. package/rispecs/borrowed_from_opencode/051-lsp-diagnostics.rispec.md +86 -0
  294. package/rispecs/borrowed_from_opencode/052-lsp-root-detection.rispec.md +109 -0
  295. package/rispecs/borrowed_from_opencode/053-remote-mcp-servers.rispec.md +119 -0
  296. package/rispecs/borrowed_from_opencode/054-mcp-oauth-flow.rispec.md +107 -0
  297. package/rispecs/borrowed_from_opencode/055-mcp-tool-conversion.rispec.md +118 -0
  298. package/rispecs/borrowed_from_opencode/056-mcp-connection-monitoring.rispec.md +106 -0
  299. package/rispecs/borrowed_from_opencode/057-local-mcp-servers.rispec.md +116 -0
  300. package/rispecs/borrowed_from_opencode/058-rich-tui.rispec.md +108 -0
  301. package/rispecs/borrowed_from_opencode/059-streaming-display.rispec.md +116 -0
  302. package/rispecs/borrowed_from_opencode/060-permission-prompts.rispec.md +130 -0
  303. package/rispecs/borrowed_from_opencode/061-session-navigation.rispec.md +155 -0
  304. package/rispecs/borrowed_from_opencode/062-syntax-highlighting.rispec.md +151 -0
  305. package/rispecs/borrowed_from_opencode/063-keybinding-system.rispec.md +181 -0
  306. package/rispecs/borrowed_from_opencode/064-multi-level-config.rispec.md +155 -0
  307. package/rispecs/borrowed_from_opencode/065-jsonc-config.rispec.md +190 -0
  308. package/rispecs/borrowed_from_opencode/066-config-env-variables.rispec.md +153 -0
  309. package/rispecs/borrowed_from_opencode/067-config-deep-merging.rispec.md +178 -0
  310. package/rispecs/borrowed_from_opencode/068-remote-org-config.rispec.md +183 -0
  311. package/rispecs/borrowed_from_opencode/069-config-markdown-frontmatter.rispec.md +206 -0
  312. package/rispecs/borrowed_from_opencode/070-managed-config-directory.rispec.md +232 -0
  313. package/rispecs/borrowed_from_opencode/071-plugin-architecture.rispec.md +104 -0
  314. package/rispecs/borrowed_from_opencode/072-plugin-hooks.rispec.md +123 -0
  315. package/rispecs/borrowed_from_opencode/073-plugin-auto-install.rispec.md +115 -0
  316. package/rispecs/borrowed_from_opencode/074-permission-system.rispec.md +133 -0
  317. package/rispecs/borrowed_from_opencode/075-git-worktree-management.rispec.md +126 -0
  318. package/rispecs/borrowed_from_opencode/076-snapshot-system.rispec.md +124 -0
  319. package/rispecs/borrowed_from_opencode/077-snapshot-diff.rispec.md +117 -0
  320. package/rispecs/borrowed_from_opencode/078-snapshot-restore.rispec.md +128 -0
  321. package/rispecs/borrowed_from_opencode/079-worktree-branch-naming.rispec.md +122 -0
  322. package/rispecs/borrowed_from_opencode/080-sqlite-storage.rispec.md +134 -0
  323. package/rispecs/borrowed_from_opencode/081-database-migrations.rispec.md +148 -0
  324. package/rispecs/borrowed_from_opencode/082-database-transactions.rispec.md +138 -0
  325. package/rispecs/borrowed_from_opencode/083-deferred-effects.rispec.md +148 -0
  326. package/rispecs/borrowed_from_opencode/084-permission-rules.rispec.md +123 -0
  327. package/rispecs/borrowed_from_opencode/085-permission-glob-patterns.rispec.md +113 -0
  328. package/rispecs/borrowed_from_opencode/086-permission-merging.rispec.md +134 -0
  329. package/rispecs/borrowed_from_opencode/087-permission-modes.rispec.md +145 -0
  330. package/rispecs/borrowed_from_opencode/088-http-api-server.rispec.md +165 -0
  331. package/rispecs/borrowed_from_opencode/089-openapi-spec-generation.rispec.md +164 -0
  332. package/rispecs/borrowed_from_opencode/090-websocket-support.rispec.md +136 -0
  333. package/rispecs/borrowed_from_opencode/091-sse-streaming.rispec.md +168 -0
  334. package/rispecs/borrowed_from_opencode/092-mdns-discovery.rispec.md +145 -0
  335. package/rispecs/borrowed_from_opencode/093-javascript-sdk.rispec.md +200 -0
  336. package/rispecs/borrowed_from_opencode/094-skill-system.rispec.md +187 -0
  337. package/rispecs/borrowed_from_opencode/095-skill-discovery.rispec.md +182 -0
  338. package/rispecs/borrowed_from_opencode/096-desktop-remote-driving.rispec.md +175 -0
  339. package/rispecs/borrowed_from_opencode/INDEX.md +255 -0
  340. package/rispecs/core.rispecs.md +261 -0
  341. package/rispecs/engines.rispecs.md +241 -0
  342. package/rispecs/formatting.rispecs.md +252 -0
  343. package/rispecs/living-specifications.rispecs.md +361 -0
  344. package/rispecs/mcp.rispecs.md +197 -0
  345. package/rispecs/pde.rispecs.md +399 -0
  346. package/rispecs/pi-mono-envisionning/ENVISIONING.md +366 -0
  347. package/rispecs/pi-mono-envisionning/storytelling-horizon.rispecs.md +76 -0
  348. package/rispecs/pi-mono-envisionning/widget.rispecs.md +2 -0
  349. package/rispecs/relation-to-mcp-structural-thinking.kin.md +72 -0
  350. package/rispecs/research-for-better-framework/CLAUDE.md +7 -0
  351. package/rispecs/research-for-better-framework/survey-pi-openclaw-opencode-openhands.md +210 -0
  352. package/rispecs/session.rispecs.md +277 -0
  353. package/rispecs/stc.rispecs.md +138 -0
  354. package/rispecs/unifier.rispecs.md +317 -0
  355. package/scripts/LAUNCH--mcp-mia-code--testing--2603141315--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +2 -0
  356. package/scripts/RESUME--mia-code--mcps--260313--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +1 -0
  357. package/scripts/install-widget-in-home-pi-agent-extensions.sh +4 -0
  358. package/scripts/sample-decompose--2604011535-prompt.sh +1 -0
  359. package/skills/deep-search/AGENTS.md +17 -0
  360. package/skills/deep-search/SKILL.md +281 -0
  361. package/skills/deep-search/agent-templates.md +224 -0
  362. package/skills/deep-search/orchestration-patterns.md +95 -0
  363. package/skills/miaco-pde-inquiry-routing-deep-search/AGENTS.md +13 -0
  364. package/skills/miaco-pde-inquiry-routing-deep-search/SKILL.md +136 -0
  365. package/skills/miaco-pde-inquiry-routing-internal-external-relationship/AGENTS.md +4 -0
  366. package/skills/miaco-pde-inquiry-routing-internal-external-relationship/SKILL.md +157 -0
  367. package/skills/miaco-pde-inquiry-routing-local-qmd/AGENTS.md +42 -0
  368. package/skills/miaco-pde-inquiry-routing-local-qmd/SKILL.md +135 -0
  369. package/skills/qmd/AGENTS.md +3 -0
  370. package/skills/qmd/SKILL.md +144 -0
  371. package/skills/qmd/references/mcp-setup.md +102 -0
  372. package/skills/rise-pde-inquiry-session-multi-agents-v3/SKILL.md +234 -0
  373. package/skills/rise-pde-inquiry-session-multi-agents-v3/agent-templates.md +436 -0
  374. package/skills/rise-pde-inquiry-session-multi-agents-v3/orchestration-patterns.md +197 -0
  375. package/skills/rise-pde-inquiry-session-multi-agents-v3/references/ceremonial-technology.md +102 -0
  376. package/skills/rise-pde-inquiry-session-multi-agents-v3/references/creative-orientation.md +99 -0
  377. package/skills/rise-pde-inquiry-session-multi-agents-v3/references/prompt-decomposition.md +73 -0
  378. package/skills/rise-pde-inquiry-session-multi-agents-v3/references/rise-framework.md +74 -0
  379. package/skills/rise-pde-inquiry-session-multi-agents-v3/references/structural-tension.md +82 -0
  380. package/src/cli.ts +35 -11
  381. package/src/geminiHeadless.ts +7 -2
  382. package/src/index.ts +2 -1
  383. package/src/mcp/miaco-server.ts +13 -1
  384. package/src/mcp/miatel-server.ts +13 -1
  385. package/src/mcp/miawa-server.ts +13 -1
  386. package/src/mcp/utils.ts +41 -8
  387. package/src/sessionStore.ts +44 -4
  388. package/src/types.ts +2 -1
  389. package/widget/mia-ceremony/README.md +36 -0
  390. package/widget/mia-ceremony/index.ts +143 -0
  391. package/widget/mia-interceptor/README.md +39 -0
  392. package/widget/mia-interceptor/index.ts +221 -0
  393. package/widget/mia-tools/README.md +37 -0
  394. package/widget/mia-tools/index.ts +569 -0
  395. package/widget/miette-echo/README.md +44 -0
  396. package/widget/miette-echo/index.ts +164 -0
  397. package/.claude/settings.local.json +0 -9
  398. package/.hch/issue_.env +0 -4
  399. package/.hch/issue_add__2601211715.json +0 -77
  400. package/.hch/issue_add__2601211715.md +0 -4
  401. package/.hch/issue_add__2602242020.json +0 -78
  402. package/.hch/issue_add__2602242020.md +0 -7
  403. package/.hch/issues.json +0 -2312
  404. package/.hch/issues.md +0 -30
  405. package/WS__mia-code__260214__IAIP_PDE.code-workspace +0 -29
  406. package/WS__mia-code__src332__260122.code-workspace +0 -23
  407. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/checkpoints/index.md +0 -6
  408. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/events.jsonl +0 -213
  409. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/plan.md +0 -243
  410. package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/workspace.yaml +0 -5
@@ -0,0 +1,187 @@
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
+ # Custom workflow
6
+
7
+ In the **custom workflow** architecture, you define your own bespoke execution flow using [LangGraph](/oss/python/langgraph/overview). You have complete control over the graph structure—including sequential steps, conditional branches, loops, and parallel execution.
8
+
9
+ ```mermaid theme={null}
10
+ graph LR
11
+ A([Input]) --> B{{Conditional}}
12
+ B -->|path_a| C[Deterministic step]
13
+ B -->|path_b| D((Agentic step))
14
+ C --> G([Output])
15
+ D --> G([Output])
16
+ ```
17
+
18
+ ## Key characteristics
19
+
20
+ * Complete control over graph structure
21
+ * Mix deterministic logic with agentic behavior
22
+ * Support for sequential steps, conditional branches, loops, and parallel execution
23
+ * Embed other patterns as nodes in your workflow
24
+
25
+ ## When to use
26
+
27
+ Use custom workflows when standard patterns (subagents, skills, etc.) don't fit your requirements, you need to mix deterministic logic with agentic behavior, or your use case requires complex routing or multi-stage processing.
28
+
29
+ Each node in your workflow can be a simple function, an LLM call, or an entire [agent](/oss/python/langchain/agents) with [tools](/oss/python/langchain/tools). You can also compose other architectures within a custom workflow—for example, embedding a multi-agent system as a single node.
30
+
31
+ For a complete example of a custom workflow, see the tutorial below.
32
+
33
+ <Card title="Tutorial: Build a multi-source knowledge base with routing" icon="book" href="/oss/python/langchain/multi-agent/router-knowledge-base" arrow cta="Learn more">
34
+ The [router pattern](/oss/python/langchain/multi-agent/router) is an example of a custom workflow. This tutorial walks through building a router that queries GitHub, Notion, and Slack in parallel, then synthesizes results.
35
+
36
+ >
37
+ </Card>
38
+
39
+ ## Basic implementation
40
+
41
+ The core insight is that you can call a LangChain agent directly inside any LangGraph node, combining the flexibility of custom workflows with the convenience of pre-built agents:
42
+
43
+ ```python theme={null}
44
+ from langchain.agents import create_agent
45
+ from langgraph.graph import StateGraph, START, END
46
+
47
+ agent = create_agent(model="openai:gpt-4.1", tools=[...])
48
+
49
+ def agent_node(state: State) -> dict:
50
+ """A LangGraph node that invokes a LangChain agent."""
51
+ result = agent.invoke({
52
+ "messages": [{"role": "user", "content": state["query"]}]
53
+ })
54
+ return {"answer": result["messages"][-1].content}
55
+
56
+ # Build a simple workflow
57
+ workflow = (
58
+ StateGraph(State)
59
+ .add_node("agent", agent_node)
60
+ .add_edge(START, "agent")
61
+ .add_edge("agent", END)
62
+ .compile()
63
+ )
64
+ ```
65
+
66
+ ## Example: RAG pipeline
67
+
68
+ A common use case is combining [retrieval](/oss/python/langchain/retrieval) with an agent. This example builds a WNBA stats assistant that retrieves from a knowledge base and can fetch live news.
69
+
70
+ <Accordion title="Custom RAG workflow">
71
+ The workflow demonstrates three types of nodes:
72
+
73
+ * **Model node** (Rewrite): Rewrites the user query for better retrieval using [structured output](/oss/python/langchain/structured-output).
74
+ * **Deterministic node** (Retrieve): Performs vector similarity search — no LLM involved.
75
+ * **Agent node** (Agent): Reasons over retrieved context and can fetch additional information via tools.
76
+
77
+ ```mermaid theme={null}
78
+ graph LR
79
+ A([Query]) --> B{{Rewrite}}
80
+ B --> C[(Retrieve)]
81
+ C --> D((Agent))
82
+ D --> E([Response])
83
+ ```
84
+
85
+ <Tip>
86
+ You can use LangGraph state to pass information between workflow steps. This allows each part of your workflow to read and update structured fields, making it easy to share data and context across nodes.
87
+ </Tip>
88
+
89
+ ```python theme={null}
90
+ from typing import TypedDict
91
+ from pydantic import BaseModel
92
+ from langgraph.graph import StateGraph, START, END
93
+ from langchain.agents import create_agent
94
+ from langchain.tools import tool
95
+ from langchain_openai import ChatOpenAI, OpenAIEmbeddings
96
+ from langchain_core.vectorstores import InMemoryVectorStore
97
+
98
+ class State(TypedDict):
99
+ question: str
100
+ rewritten_query: str
101
+ documents: list[str]
102
+ answer: str
103
+
104
+ # WNBA knowledge base with rosters, game results, and player stats
105
+ embeddings = OpenAIEmbeddings()
106
+ vector_store = InMemoryVectorStore(embeddings)
107
+ vector_store.add_texts([
108
+ # Rosters
109
+ "New York Liberty 2024 roster: Breanna Stewart, Sabrina Ionescu, Jonquel Jones, Courtney Vandersloot.",
110
+ "Las Vegas Aces 2024 roster: A'ja Wilson, Kelsey Plum, Jackie Young, Chelsea Gray.",
111
+ "Indiana Fever 2024 roster: Caitlin Clark, Aliyah Boston, Kelsey Mitchell, NaLyssa Smith.",
112
+ # Game results
113
+ "2024 WNBA Finals: New York Liberty defeated Minnesota Lynx 3-2 to win the championship.",
114
+ "June 15, 2024: Indiana Fever 85, Chicago Sky 79. Caitlin Clark had 23 points and 8 assists.",
115
+ "August 20, 2024: Las Vegas Aces 92, Phoenix Mercury 84. A'ja Wilson scored 35 points.",
116
+ # Player stats
117
+ "A'ja Wilson 2024 season stats: 26.9 PPG, 11.9 RPG, 2.6 BPG. Won MVP award.",
118
+ "Caitlin Clark 2024 rookie stats: 19.2 PPG, 8.4 APG, 5.7 RPG. Won Rookie of the Year.",
119
+ "Breanna Stewart 2024 stats: 20.4 PPG, 8.5 RPG, 3.5 APG.",
120
+ ])
121
+ retriever = vector_store.as_retriever(search_kwargs={"k": 5})
122
+
123
+ @tool
124
+ def get_latest_news(query: str) -> str:
125
+ """Get the latest WNBA news and updates."""
126
+ # Your news API here
127
+ return "Latest: The WNBA announced expanded playoff format for 2025..."
128
+
129
+ agent = create_agent(
130
+ model="openai:gpt-4.1",
131
+ tools=[get_latest_news],
132
+ )
133
+
134
+ model = ChatOpenAI(model="gpt-4.1")
135
+
136
+ class RewrittenQuery(BaseModel):
137
+ query: str
138
+
139
+ def rewrite_query(state: State) -> dict:
140
+ """Rewrite the user query for better retrieval."""
141
+ system_prompt = """Rewrite this query to retrieve relevant WNBA information.
142
+ The knowledge base contains: team rosters, game results with scores, and player statistics (PPG, RPG, APG).
143
+ Focus on specific player names, team names, or stat categories mentioned."""
144
+ response = model.with_structured_output(RewrittenQuery).invoke([
145
+ {"role": "system", "content": system_prompt},
146
+ {"role": "user", "content": state["question"]}
147
+ ])
148
+ return {"rewritten_query": response.query}
149
+
150
+ def retrieve(state: State) -> dict:
151
+ """Retrieve documents based on the rewritten query."""
152
+ docs = retriever.invoke(state["rewritten_query"])
153
+ return {"documents": [doc.page_content for doc in docs]}
154
+
155
+ def call_agent(state: State) -> dict:
156
+ """Generate answer using retrieved context."""
157
+ context = "\n\n".join(state["documents"])
158
+ prompt = f"Context:\n{context}\n\nQuestion: {state['question']}"
159
+ response = agent.invoke({"messages": [{"role": "user", "content": prompt}]})
160
+ return {"answer": response["messages"][-1].content_blocks}
161
+
162
+ workflow = (
163
+ StateGraph(State)
164
+ .add_node("rewrite", rewrite_query)
165
+ .add_node("retrieve", retrieve)
166
+ .add_node("agent", call_agent)
167
+ .add_edge(START, "rewrite")
168
+ .add_edge("rewrite", "retrieve")
169
+ .add_edge("retrieve", "agent")
170
+ .add_edge("agent", END)
171
+ .compile()
172
+ )
173
+
174
+ result = workflow.invoke({"question": "Who won the 2024 WNBA Championship?"})
175
+ print(result["answer"])
176
+ ```
177
+ </Accordion>
178
+
179
+ ***
180
+
181
+ <Callout icon="pen-to-square" iconType="regular">
182
+ [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/multi-agent/custom-workflow.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
183
+ </Callout>
184
+
185
+ <Tip icon="terminal" iconType="regular">
186
+ [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
187
+ </Tip>
@@ -0,0 +1,436 @@
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
+ # Handoffs
6
+
7
+ In the **handoffs** architecture, behavior changes dynamically based on state. The core mechanism: [tools](/oss/python/langchain/tools) update a state variable (e.g., `current_step` or `active_agent`) that persists across turns, and the system reads this variable to adjust behavior—either applying different configuration (system prompt, tools) or routing to a different [agent](/oss/python/langchain/agents). This pattern supports both handoffs between distinct agents and dynamic configuration changes within a single agent.
8
+
9
+ <Tip>
10
+ The term **handoffs** was coined by [OpenAI](https://openai.github.io/openai-agents-python/handoffs/) for using tool calls (e.g., `transfer_to_sales_agent`) to transfer control between agents or states.
11
+ </Tip>
12
+
13
+ ```mermaid theme={null}
14
+ sequenceDiagram
15
+ participant User
16
+ participant Agent
17
+ participant Workflow State
18
+
19
+ User->>Agent: "My phone is broken"
20
+ Note over Agent,Workflow State: Step: Get warranty status<br/>Tools: record_warranty_status
21
+ Agent-->>User: "Is your device under warranty?"
22
+
23
+ User->>Agent: "Yes, it's still under warranty"
24
+ Agent->>Workflow State: record_warranty_status("in_warranty")
25
+ Note over Agent,Workflow State: Step: Classify issue<br/>Tools: record_issue_type
26
+ Agent-->>User: "Can you describe the issue?"
27
+
28
+ User->>Agent: "The screen is cracked"
29
+ Agent->>Workflow State: record_issue_type("hardware")
30
+ Note over Agent,Workflow State: Step: Provide resolution<br/>Tools: provide_solution, escalate_to_human
31
+ Agent-->>User: "Here's the warranty repair process..."
32
+ ```
33
+
34
+ ## Key characteristics
35
+
36
+ * State-driven behavior: Behavior changes based on a state variable (e.g., `current_step` or `active_agent`)
37
+ * Tool-based transitions: Tools update the state variable to move between states
38
+ * Direct user interaction: Each state's configuration handles user messages directly
39
+ * Persistent state: State survives across conversation turns
40
+
41
+ ## When to use
42
+
43
+ Use the handoffs pattern when you need to enforce sequential constraints (unlock capabilities only after preconditions are met), the agent needs to converse directly with the user across different states, or you're building multi-stage conversational flows. This pattern is particularly valuable for customer support scenarios where you need to collect information in a specific sequence — for example, collecting a warranty ID before processing a refund.
44
+
45
+ ## Basic implementation
46
+
47
+ The core mechanism is a [tool](/oss/python/langchain/tools) that returns a [`Command`](/oss/python/langgraph/graph-api#command) to update state, triggering a transition to a new step or agent:
48
+
49
+ ```python theme={null}
50
+ from langchain.tools import tool
51
+ from langchain.messages import ToolMessage
52
+ from langgraph.types import Command
53
+
54
+ @tool
55
+ def transfer_to_specialist(runtime) -> Command:
56
+ """Transfer to the specialist agent."""
57
+ return Command(
58
+ update={
59
+ "messages": [
60
+ ToolMessage( # [!code highlight]
61
+ content="Transferred to specialist",
62
+ tool_call_id=runtime.tool_call_id # [!code highlight]
63
+ )
64
+ ],
65
+ "current_step": "specialist" # Triggers behavior change
66
+ }
67
+ )
68
+ ```
69
+
70
+ <Note>
71
+ **Why include a `ToolMessage`?** When an LLM calls a tool, it expects a response. The `ToolMessage` with matching `tool_call_id` completes this request-response cycle—without it, the conversation history becomes malformed. This is required whenever your handoff tool updates messages.
72
+ </Note>
73
+
74
+ For a complete implementation, see the tutorial below.
75
+
76
+ <Card title="Tutorial: Build customer support with handoffs" icon="people-arrows" href="/oss/python/langchain/multi-agent/handoffs-customer-support" arrow cta="Learn more">
77
+ Learn how to build a customer support agent using the handoffs pattern, where a single agent transitions between different configurations.
78
+ </Card>
79
+
80
+ ## Implementation approaches
81
+
82
+ There are two ways to implement handoffs: **[single agent with middleware](#single-agent-with-middleware)** (one agent with dynamic configuration) or **[multiple agent subgraphs](#multiple-agent-subgraphs)** (distinct agents as graph nodes).
83
+
84
+ ### Single agent with middleware
85
+
86
+ A single agent changes its behavior based on state. Middleware intercepts each model call and dynamically adjusts the system prompt and available tools. Tools update the state variable to trigger transitions:
87
+
88
+ ```python theme={null}
89
+ from langchain.tools import ToolRuntime, tool
90
+ from langchain.messages import ToolMessage
91
+ from langgraph.types import Command
92
+
93
+ @tool
94
+ def record_warranty_status(
95
+ status: str,
96
+ runtime: ToolRuntime[None, SupportState]
97
+ ) -> Command:
98
+ """Record warranty status and transition to next step."""
99
+ return Command(
100
+ update={
101
+ "messages": [
102
+ ToolMessage(
103
+ content=f"Warranty status recorded: {status}",
104
+ tool_call_id=runtime.tool_call_id
105
+ )
106
+ ],
107
+ "warranty_status": status,
108
+ "current_step": "specialist" # Update state to trigger transition
109
+ }
110
+ )
111
+ ```
112
+
113
+ <Accordion title="Complete example: Customer support with middleware">
114
+ ```python theme={null}
115
+ from langchain.agents import AgentState, create_agent
116
+ from langchain.agents.middleware import wrap_model_call, ModelRequest, ModelResponse
117
+ from langchain.tools import tool, ToolRuntime
118
+ from langchain.messages import ToolMessage
119
+ from langgraph.types import Command
120
+ from typing import Callable
121
+
122
+ # 1. Define state with current_step tracker
123
+ class SupportState(AgentState): # [!code highlight]
124
+ """Track which step is currently active."""
125
+ current_step: str = "triage" # [!code highlight]
126
+ warranty_status: str | None = None
127
+
128
+ # 2. Tools update current_step via Command
129
+ @tool
130
+ def record_warranty_status(
131
+ status: str,
132
+ runtime: ToolRuntime[None, SupportState]
133
+ ) -> Command: # [!code highlight]
134
+ """Record warranty status and transition to next step."""
135
+ return Command(update={ # [!code highlight]
136
+ "messages": [ # [!code highlight]
137
+ ToolMessage(
138
+ content=f"Warranty status recorded: {status}",
139
+ tool_call_id=runtime.tool_call_id
140
+ )
141
+ ],
142
+ "warranty_status": status,
143
+ # Transition to next step
144
+ "current_step": "specialist" # [!code highlight]
145
+ })
146
+
147
+ # 3. Middleware applies dynamic configuration based on current_step
148
+ @wrap_model_call # [!code highlight]
149
+ def apply_step_config(
150
+ request: ModelRequest,
151
+ handler: Callable[[ModelRequest], ModelResponse]
152
+ ) -> ModelResponse:
153
+ """Configure agent behavior based on current_step."""
154
+ step = request.state.get("current_step", "triage") # [!code highlight]
155
+
156
+ # Map steps to their configurations
157
+ configs = {
158
+ "triage": {
159
+ "prompt": "Collect warranty information...",
160
+ "tools": [record_warranty_status]
161
+ },
162
+ "specialist": {
163
+ "prompt": "Provide solutions based on warranty: {warranty_status}",
164
+ "tools": [provide_solution, escalate]
165
+ }
166
+ }
167
+
168
+ config = configs[step]
169
+ request = request.override( # [!code highlight]
170
+ system_prompt=config["prompt"].format(**request.state), # [!code highlight]
171
+ tools=config["tools"] # [!code highlight]
172
+ )
173
+ return handler(request)
174
+
175
+ # 4. Create agent with middleware
176
+ agent = create_agent(
177
+ model,
178
+ tools=[record_warranty_status, provide_solution, escalate],
179
+ state_schema=SupportState,
180
+ middleware=[apply_step_config], # [!code highlight]
181
+ checkpointer=InMemorySaver() # Persist state across turns # [!code highlight]
182
+ )
183
+ ```
184
+ </Accordion>
185
+
186
+ ### Multiple agent subgraphs
187
+
188
+ Multiple distinct agents exist as separate nodes in a graph. Handoff tools navigate between agent nodes using `Command.PARENT` to specify which node to execute next.
189
+
190
+ <Warning>
191
+ Subgraph handoffs require careful **[context engineering](/oss/python/langchain/context-engineering)**. Unlike single-agent middleware (where message history flows naturally), you must explicitly decide what messages pass between agents. Get this wrong and agents receive malformed conversation history or bloated context. See [Context engineering](#context-engineering) below.
192
+ </Warning>
193
+
194
+ ```python theme={null}
195
+ from langchain.messages import AIMessage, ToolMessage
196
+ from langchain.tools import tool, ToolRuntime
197
+ from langgraph.types import Command
198
+
199
+ @tool
200
+ def transfer_to_sales(
201
+ runtime: ToolRuntime,
202
+ ) -> Command:
203
+ """Transfer to the sales agent."""
204
+ last_ai_message = next( # [!code highlight]
205
+ msg for msg in reversed(runtime.state["messages"]) if isinstance(msg, AIMessage) # [!code highlight]
206
+ ) # [!code highlight]
207
+ transfer_message = ToolMessage( # [!code highlight]
208
+ content="Transferred to sales agent", # [!code highlight]
209
+ tool_call_id=runtime.tool_call_id, # [!code highlight]
210
+ ) # [!code highlight]
211
+ return Command(
212
+ goto="sales_agent",
213
+ update={
214
+ "active_agent": "sales_agent",
215
+ "messages": [last_ai_message, transfer_message], # [!code highlight]
216
+ },
217
+ graph=Command.PARENT
218
+ )
219
+ ```
220
+
221
+ <Accordion title="Complete example: Sales and support with handoffs">
222
+ This example shows a multi-agent system with separate sales and support agents. Each agent is a separate graph node, and handoff tools allow agents to transfer conversations to each other.
223
+
224
+ ```python theme={null}
225
+ from typing import Literal
226
+
227
+ from langchain.agents import AgentState, create_agent
228
+ from langchain.messages import AIMessage, ToolMessage
229
+ from langchain.tools import tool, ToolRuntime
230
+ from langgraph.graph import StateGraph, START, END
231
+ from langgraph.types import Command
232
+ from typing_extensions import NotRequired
233
+
234
+
235
+ # 1. Define state with active_agent tracker
236
+ class MultiAgentState(AgentState):
237
+ active_agent: NotRequired[str]
238
+
239
+
240
+ # 2. Create handoff tools
241
+ @tool
242
+ def transfer_to_sales(
243
+ runtime: ToolRuntime,
244
+ ) -> Command:
245
+ """Transfer to the sales agent."""
246
+ last_ai_message = next( # [!code highlight]
247
+ msg for msg in reversed(runtime.state["messages"]) if isinstance(msg, AIMessage) # [!code highlight]
248
+ ) # [!code highlight]
249
+ transfer_message = ToolMessage( # [!code highlight]
250
+ content="Transferred to sales agent from support agent", # [!code highlight]
251
+ tool_call_id=runtime.tool_call_id, # [!code highlight]
252
+ ) # [!code highlight]
253
+ return Command(
254
+ goto="sales_agent",
255
+ update={
256
+ "active_agent": "sales_agent",
257
+ "messages": [last_ai_message, transfer_message], # [!code highlight]
258
+ },
259
+ graph=Command.PARENT,
260
+ )
261
+
262
+
263
+ @tool
264
+ def transfer_to_support(
265
+ runtime: ToolRuntime,
266
+ ) -> Command:
267
+ """Transfer to the support agent."""
268
+ last_ai_message = next( # [!code highlight]
269
+ msg for msg in reversed(runtime.state["messages"]) if isinstance(msg, AIMessage) # [!code highlight]
270
+ ) # [!code highlight]
271
+ transfer_message = ToolMessage( # [!code highlight]
272
+ content="Transferred to support agent from sales agent", # [!code highlight]
273
+ tool_call_id=runtime.tool_call_id, # [!code highlight]
274
+ ) # [!code highlight]
275
+ return Command(
276
+ goto="support_agent",
277
+ update={
278
+ "active_agent": "support_agent",
279
+ "messages": [last_ai_message, transfer_message], # [!code highlight]
280
+ },
281
+ graph=Command.PARENT,
282
+ )
283
+
284
+
285
+ # 3. Create agents with handoff tools
286
+ sales_agent = create_agent(
287
+ model="anthropic:claude-sonnet-4-20250514",
288
+ tools=[transfer_to_support],
289
+ system_prompt="You are a sales agent. Help with sales inquiries. If asked about technical issues or support, transfer to the support agent.",
290
+ )
291
+
292
+ support_agent = create_agent(
293
+ model="anthropic:claude-sonnet-4-20250514",
294
+ tools=[transfer_to_sales],
295
+ system_prompt="You are a support agent. Help with technical issues. If asked about pricing or purchasing, transfer to the sales agent.",
296
+ )
297
+
298
+
299
+ # 4. Create agent nodes that invoke the agents
300
+ def call_sales_agent(state: MultiAgentState) -> Command:
301
+ """Node that calls the sales agent."""
302
+ response = sales_agent.invoke(state)
303
+ return response
304
+
305
+
306
+ def call_support_agent(state: MultiAgentState) -> Command:
307
+ """Node that calls the support agent."""
308
+ response = support_agent.invoke(state)
309
+ return response
310
+
311
+
312
+ # 5. Create router that checks if we should end or continue
313
+ def route_after_agent(
314
+ state: MultiAgentState,
315
+ ) -> Literal["sales_agent", "support_agent", "__end__"]:
316
+ """Route based on active_agent, or END if the agent finished without handoff."""
317
+ messages = state.get("messages", [])
318
+
319
+ # Check the last message - if it's an AIMessage without tool calls, we're done
320
+ if messages:
321
+ last_msg = messages[-1]
322
+ if isinstance(last_msg, AIMessage) and not last_msg.tool_calls: # [!code highlight]
323
+ return "__end__" # [!code highlight]
324
+
325
+ # Otherwise route to the active agent
326
+ active = state.get("active_agent", "sales_agent")
327
+ return active if active else "sales_agent"
328
+
329
+
330
+ def route_initial(
331
+ state: MultiAgentState,
332
+ ) -> Literal["sales_agent", "support_agent"]:
333
+ """Route to the active agent based on state, default to sales agent."""
334
+ return state.get("active_agent") or "sales_agent"
335
+
336
+
337
+ # 6. Build the graph
338
+ builder = StateGraph(MultiAgentState)
339
+ builder.add_node("sales_agent", call_sales_agent)
340
+ builder.add_node("support_agent", call_support_agent)
341
+
342
+ # Start with conditional routing based on initial active_agent
343
+ builder.add_conditional_edges(START, route_initial, ["sales_agent", "support_agent"])
344
+
345
+ # After each agent, check if we should end or route to another agent
346
+ builder.add_conditional_edges(
347
+ "sales_agent", route_after_agent, ["sales_agent", "support_agent", END]
348
+ )
349
+ builder.add_conditional_edges(
350
+ "support_agent", route_after_agent, ["sales_agent", "support_agent", END]
351
+ )
352
+
353
+ graph = builder.compile()
354
+ result = graph.invoke(
355
+ {
356
+ "messages": [
357
+ {
358
+ "role": "user",
359
+ "content": "Hi, I'm having trouble with my account login. Can you help?",
360
+ }
361
+ ]
362
+ }
363
+ )
364
+
365
+ for msg in result["messages"]:
366
+ msg.pretty_print()
367
+ ```
368
+ </Accordion>
369
+
370
+ <Tip>
371
+ Use **single agent with middleware** for most handoffs use cases—it's simpler. Only use **multiple agent subgraphs** when you need bespoke agent implementations (e.g., a node that's itself a complex graph with reflection or retrieval steps).
372
+ </Tip>
373
+
374
+ #### Context engineering
375
+
376
+ With subgraph handoffs, you control exactly what messages flow between agents. This precision is essential for maintaining valid conversation history and avoiding context bloat that could confuse downstream agents. For more on this topic, see [context engineering](/oss/python/langchain/context-engineering).
377
+
378
+ **Handling context during handoffs**
379
+
380
+ When handing off between agents, you need to ensure the conversation history remains valid. LLMs expect tool calls to be paired with their responses, so when using `Command.PARENT` to hand off to another agent, you must include both:
381
+
382
+ 1. **The `AIMessage` containing the tool call** (the message that triggered the handoff)
383
+ 2. **A `ToolMessage` acknowledging the handoff** (the artificial response to that tool call)
384
+
385
+ Without this pairing, the receiving agent will see an incomplete conversation and may produce errors or unexpected behavior.
386
+
387
+ The example below assumes only the handoff tool was called (no parallel tool calls):
388
+
389
+ ```python theme={null}
390
+ @tool
391
+ def transfer_to_sales(runtime: ToolRuntime) -> Command:
392
+ # Get the AI message that triggered this handoff
393
+ last_ai_message = runtime.state["messages"][-1]
394
+
395
+ # Create an artificial tool response to complete the pair
396
+ transfer_message = ToolMessage(
397
+ content="Transferred to sales agent",
398
+ tool_call_id=runtime.tool_call_id,
399
+ )
400
+
401
+ return Command(
402
+ goto="sales_agent",
403
+ update={
404
+ "active_agent": "sales_agent",
405
+ # Pass only these two messages, not the full subagent history
406
+ "messages": [last_ai_message, transfer_message],
407
+ },
408
+ graph=Command.PARENT,
409
+ )
410
+ ```
411
+
412
+ <Note>
413
+ **Why not pass all subagent messages?** While you could include the full subagent conversation in the handoff, this often creates problems. The receiving agent may become confused by irrelevant internal reasoning, and token costs increase unnecessarily. By passing only the handoff pair, you keep the parent graph's context focused on high-level coordination. If the receiving agent needs additional context, consider summarizing the subagent's work in the ToolMessage content instead of passing raw message history.
414
+ </Note>
415
+
416
+ **Returning control to the user**
417
+
418
+ When returning control to the user (ending the agent's turn), ensure the final message is an `AIMessage`. This maintains valid conversation history and signals to the user interface that the agent has finished its work.
419
+
420
+ ## Implementation considerations
421
+
422
+ As you design your multi-agent system, consider:
423
+
424
+ * **Context filtering strategy**: Will each agent receive full conversation history, filtered portions, or summaries? Different agents may need different context depending on their role.
425
+ * **Tool semantics**: Clarify whether handoff tools only update routing state or also perform side effects. For example, should `transfer_to_sales()` also create a support ticket, or should that be a separate action?
426
+ * **Token efficiency**: Balance context completeness against token costs. Summarization and selective context passing become more important as conversations grow longer.
427
+
428
+ ***
429
+
430
+ <Callout icon="pen-to-square" iconType="regular">
431
+ [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/multi-agent/handoffs.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
432
+ </Callout>
433
+
434
+ <Tip icon="terminal" iconType="regular">
435
+ [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
436
+ </Tip>