[{"data":1,"prerenderedAt":790},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fv2\u002Fapi\u002Fthread":3},{"id":4,"title":5,"body":6,"description":783,"extension":784,"meta":785,"navigation":191,"path":786,"seo":787,"stem":788,"__hash__":789},"docs\u002Fdocs\u002Fv2\u002Fapi\u002Fthread.md","axon.thread",{"type":7,"value":8,"toc":776},"minimark",[9,13,26,31,38,148,151,155,158,363,366,370,383,492,496,499,662,666,669,769,772],[10,11,5],"h1",{"id":12},"axonthread",[14,15,16,17,21,22,25],"p",{},"Every ",[18,19,20],"code",{},"axon.request"," and ",[18,23,24],{},"axon.stream"," call runs inside a thread. A thread is a\nconversation history — the agent sees all prior entries when you continue it.",[27,28,30],"h2",{"id":29},"the-execution-thread","The execution thread",[14,32,33,34,37],{},"Omitting ",[18,35,36],{},"thread"," continues the script's own execution thread. Consecutive calls\nshare context automatically.",[39,40,45],"pre",{"className":41,"code":42,"language":43,"meta":44,"style":44},"language-ts shiki shiki-themes dark-plus","const r1 = await axon.request(\"hello\")\nconst r2 = await axon.request(\"say cheese\")   \u002F\u002F agent remembers r1\nconst r3 = await axon.request(\"tell a joke\")  \u002F\u002F agent remembers r1 and r2\n","ts","",[18,46,47,89,119],{"__ignoreMap":44},[48,49,52,56,60,64,68,72,75,79,82,86],"span",{"class":50,"line":51},"line",1,[48,53,55],{"class":54},"scz_3","const",[48,57,59],{"class":58},"s9McN"," r1",[48,61,63],{"class":62},"sTNBD"," = ",[48,65,67],{"class":66},"sYbnZ","await",[48,69,71],{"class":70},"s3F5K"," axon",[48,73,74],{"class":62},".",[48,76,78],{"class":77},"sCudf","request",[48,80,81],{"class":62},"(",[48,83,85],{"class":84},"sKc5r","\"hello\"",[48,87,88],{"class":62},")\n",[48,90,92,94,97,99,101,103,105,107,109,112,115],{"class":50,"line":91},2,[48,93,55],{"class":54},[48,95,96],{"class":58}," r2",[48,98,63],{"class":62},[48,100,67],{"class":66},[48,102,71],{"class":70},[48,104,74],{"class":62},[48,106,78],{"class":77},[48,108,81],{"class":62},[48,110,111],{"class":84},"\"say cheese\"",[48,113,114],{"class":62},")   ",[48,116,118],{"class":117},"sOLPB","\u002F\u002F agent remembers r1\n",[48,120,122,124,127,129,131,133,135,137,139,142,145],{"class":50,"line":121},3,[48,123,55],{"class":54},[48,125,126],{"class":58}," r3",[48,128,63],{"class":62},[48,130,67],{"class":66},[48,132,71],{"class":70},[48,134,74],{"class":62},[48,136,78],{"class":77},[48,138,81],{"class":62},[48,140,141],{"class":84},"\"tell a joke\"",[48,143,144],{"class":62},")  ",[48,146,147],{"class":117},"\u002F\u002F agent remembers r1 and r2\n",[14,149,150],{},"This is the default. Most scripts that do one focused task never need anything else.",[27,152,154],{"id":153},"named-threads","Named threads",[14,156,157],{},"Pass a string name to run a call in an isolated side thread. The runtime resolves\nthe name to a stable ID for this session. Named threads don't share context with\nthe execution thread or with each other.",[39,159,161],{"className":41,"code":160,"language":43,"meta":44,"style":44},"const main = await axon.request(\"starting the main task\")\n\nconst lookup = await axon.request({\n    prompt: \"what's the capital of france\",\n    thread: \"geo-lookup\",\n})\n\nconst followup = await axon.request({\n    prompt: \"what's the population of that city\",\n    thread: \"geo-lookup\",   \u002F\u002F agent has r1 on this thread — knows \"that city\"\n})\n\n\u002F\u002F inject result back into main thread\nconst summary = await axon.request(\n    `incorporate this: ${followup.text}`,\n    \u002F\u002F no thread: — back on the execution thread\n)\n",[18,162,163,187,193,213,225,236,242,247,267,277,290,295,300,306,327,352,358],{"__ignoreMap":44},[48,164,165,167,170,172,174,176,178,180,182,185],{"class":50,"line":51},[48,166,55],{"class":54},[48,168,169],{"class":58}," main",[48,171,63],{"class":62},[48,173,67],{"class":66},[48,175,71],{"class":70},[48,177,74],{"class":62},[48,179,78],{"class":77},[48,181,81],{"class":62},[48,183,184],{"class":84},"\"starting the main task\"",[48,186,88],{"class":62},[48,188,189],{"class":50,"line":91},[48,190,192],{"emptyLinePlaceholder":191},true,"\n",[48,194,195,197,200,202,204,206,208,210],{"class":50,"line":121},[48,196,55],{"class":54},[48,198,199],{"class":58}," lookup",[48,201,63],{"class":62},[48,203,67],{"class":66},[48,205,71],{"class":70},[48,207,74],{"class":62},[48,209,78],{"class":77},[48,211,212],{"class":62},"({\n",[48,214,216,219,222],{"class":50,"line":215},4,[48,217,218],{"class":70},"    prompt:",[48,220,221],{"class":84}," \"what's the capital of france\"",[48,223,224],{"class":62},",\n",[48,226,228,231,234],{"class":50,"line":227},5,[48,229,230],{"class":70},"    thread:",[48,232,233],{"class":84}," \"geo-lookup\"",[48,235,224],{"class":62},[48,237,239],{"class":50,"line":238},6,[48,240,241],{"class":62},"})\n",[48,243,245],{"class":50,"line":244},7,[48,246,192],{"emptyLinePlaceholder":191},[48,248,250,252,255,257,259,261,263,265],{"class":50,"line":249},8,[48,251,55],{"class":54},[48,253,254],{"class":58}," followup",[48,256,63],{"class":62},[48,258,67],{"class":66},[48,260,71],{"class":70},[48,262,74],{"class":62},[48,264,78],{"class":77},[48,266,212],{"class":62},[48,268,270,272,275],{"class":50,"line":269},9,[48,271,218],{"class":70},[48,273,274],{"class":84}," \"what's the population of that city\"",[48,276,224],{"class":62},[48,278,280,282,284,287],{"class":50,"line":279},10,[48,281,230],{"class":70},[48,283,233],{"class":84},[48,285,286],{"class":62},",   ",[48,288,289],{"class":117},"\u002F\u002F agent has r1 on this thread — knows \"that city\"\n",[48,291,293],{"class":50,"line":292},11,[48,294,241],{"class":62},[48,296,298],{"class":50,"line":297},12,[48,299,192],{"emptyLinePlaceholder":191},[48,301,303],{"class":50,"line":302},13,[48,304,305],{"class":117},"\u002F\u002F inject result back into main thread\n",[48,307,309,311,314,316,318,320,322,324],{"class":50,"line":308},14,[48,310,55],{"class":54},[48,312,313],{"class":58}," summary",[48,315,63],{"class":62},[48,317,67],{"class":66},[48,319,71],{"class":70},[48,321,74],{"class":62},[48,323,78],{"class":77},[48,325,326],{"class":62},"(\n",[48,328,330,333,336,339,341,344,347,350],{"class":50,"line":329},15,[48,331,332],{"class":84},"    `incorporate this: ",[48,334,335],{"class":54},"${",[48,337,338],{"class":70},"followup",[48,340,74],{"class":62},[48,342,343],{"class":70},"text",[48,345,346],{"class":54},"}",[48,348,349],{"class":84},"`",[48,351,224],{"class":62},[48,353,355],{"class":50,"line":354},16,[48,356,357],{"class":117},"    \u002F\u002F no thread: — back on the execution thread\n",[48,359,361],{"class":50,"line":360},17,[48,362,88],{"class":62},[14,364,365],{},"Named threads are for work that needs its own clean context: research tasks, side\nlookups, parallel branches. They prevent unrelated content from polluting the\nagent's working memory on the main thread.",[27,367,369],{"id":368},"thread-handle","Thread handle",[14,371,372,373,21,376,379,380,382],{},"For repeated calls to the same named thread, a handle avoids repeating the name on\nevery call. ",[18,374,375],{},".request()",[18,377,378],{},".stream()"," have the same signatures as the top-level\ncalls, minus the ",[18,381,36],{}," field.",[39,384,386],{"className":41,"code":385,"language":43,"meta":44,"style":44},"const research = axon.thread(\"research\")\n\nawait research.request(\"find everything about the eiffel tower\")\nawait research.request(\"now find the history of its construction\")\nawait research.request(\"summarise into 3 bullet points\")\n\n\u002F\u002F full entry timeline for this thread\nconst timeline = research.entries\n",[18,387,388,411,415,432,449,466,470,475],{"__ignoreMap":44},[48,389,390,392,395,397,400,402,404,406,409],{"class":50,"line":51},[48,391,55],{"class":54},[48,393,394],{"class":58}," research",[48,396,63],{"class":62},[48,398,399],{"class":70},"axon",[48,401,74],{"class":62},[48,403,36],{"class":77},[48,405,81],{"class":62},[48,407,408],{"class":84},"\"research\"",[48,410,88],{"class":62},[48,412,413],{"class":50,"line":91},[48,414,192],{"emptyLinePlaceholder":191},[48,416,417,419,421,423,425,427,430],{"class":50,"line":121},[48,418,67],{"class":66},[48,420,394],{"class":70},[48,422,74],{"class":62},[48,424,78],{"class":77},[48,426,81],{"class":62},[48,428,429],{"class":84},"\"find everything about the eiffel tower\"",[48,431,88],{"class":62},[48,433,434,436,438,440,442,444,447],{"class":50,"line":215},[48,435,67],{"class":66},[48,437,394],{"class":70},[48,439,74],{"class":62},[48,441,78],{"class":77},[48,443,81],{"class":62},[48,445,446],{"class":84},"\"now find the history of its construction\"",[48,448,88],{"class":62},[48,450,451,453,455,457,459,461,464],{"class":50,"line":227},[48,452,67],{"class":66},[48,454,394],{"class":70},[48,456,74],{"class":62},[48,458,78],{"class":77},[48,460,81],{"class":62},[48,462,463],{"class":84},"\"summarise into 3 bullet points\"",[48,465,88],{"class":62},[48,467,468],{"class":50,"line":238},[48,469,192],{"emptyLinePlaceholder":191},[48,471,472],{"class":50,"line":244},[48,473,474],{"class":117},"\u002F\u002F full entry timeline for this thread\n",[48,476,477,479,482,484,487,489],{"class":50,"line":249},[48,478,55],{"class":54},[48,480,481],{"class":58}," timeline",[48,483,63],{"class":62},[48,485,486],{"class":70},"research",[48,488,74],{"class":62},[48,490,491],{"class":70},"entries\n",[27,493,495],{"id":494},"parallel-branches","Parallel branches",[14,497,498],{},"Multiple named threads run concurrently. Pull results back into the main thread for\nsynthesis.",[39,500,502],{"className":41,"code":501,"language":43,"meta":44,"style":44},"const [a, b] = await Promise.all([\n    axon.request({ prompt: \"research quantum computing\", thread: \"task-a\" }),\n    axon.request({ prompt: \"research classical computing\", thread: \"task-b\" }),\n])\n\nconst synthesis = await axon.request(\n    `compare these two:\\n\\nA: ${a.text}\\n\\nB: ${b.text}`\n)\n",[18,503,504,537,566,590,595,599,618,658],{"__ignoreMap":44},[48,505,506,508,511,514,517,520,523,525,529,531,534],{"class":50,"line":51},[48,507,55],{"class":54},[48,509,510],{"class":62}," [",[48,512,513],{"class":58},"a",[48,515,516],{"class":62},", ",[48,518,519],{"class":58},"b",[48,521,522],{"class":62},"] = ",[48,524,67],{"class":66},[48,526,528],{"class":527},"sNl3T"," Promise",[48,530,74],{"class":62},[48,532,533],{"class":77},"all",[48,535,536],{"class":62},"([\n",[48,538,539,542,544,546,549,552,555,557,560,563],{"class":50,"line":91},[48,540,541],{"class":70},"    axon",[48,543,74],{"class":62},[48,545,78],{"class":77},[48,547,548],{"class":62},"({ ",[48,550,551],{"class":70},"prompt:",[48,553,554],{"class":84}," \"research quantum computing\"",[48,556,516],{"class":62},[48,558,559],{"class":70},"thread:",[48,561,562],{"class":84}," \"task-a\"",[48,564,565],{"class":62}," }),\n",[48,567,568,570,572,574,576,578,581,583,585,588],{"class":50,"line":121},[48,569,541],{"class":70},[48,571,74],{"class":62},[48,573,78],{"class":77},[48,575,548],{"class":62},[48,577,551],{"class":70},[48,579,580],{"class":84}," \"research classical computing\"",[48,582,516],{"class":62},[48,584,559],{"class":70},[48,586,587],{"class":84}," \"task-b\"",[48,589,565],{"class":62},[48,591,592],{"class":50,"line":215},[48,593,594],{"class":62},"])\n",[48,596,597],{"class":50,"line":227},[48,598,192],{"emptyLinePlaceholder":191},[48,600,601,603,606,608,610,612,614,616],{"class":50,"line":238},[48,602,55],{"class":54},[48,604,605],{"class":58}," synthesis",[48,607,63],{"class":62},[48,609,67],{"class":66},[48,611,71],{"class":70},[48,613,74],{"class":62},[48,615,78],{"class":77},[48,617,326],{"class":62},[48,619,620,623,627,630,632,634,636,638,640,642,645,647,649,651,653,655],{"class":50,"line":244},[48,621,622],{"class":84},"    `compare these two:",[48,624,626],{"class":625},"svVle","\\n\\n",[48,628,629],{"class":84},"A: ",[48,631,335],{"class":54},[48,633,513],{"class":70},[48,635,74],{"class":62},[48,637,343],{"class":70},[48,639,346],{"class":54},[48,641,626],{"class":625},[48,643,644],{"class":84},"B: ",[48,646,335],{"class":54},[48,648,519],{"class":70},[48,650,74],{"class":62},[48,652,343],{"class":70},[48,654,346],{"class":54},[48,656,657],{"class":84},"`\n",[48,659,660],{"class":50,"line":249},[48,661,88],{"class":62},[27,663,665],{"id":664},"persistence-across-script-runs","Persistence across script runs",[14,667,668],{},"Named threads are persisted server-side within the session. The same thread name on\nthe next script run resumes with full prior context intact.",[39,670,672],{"className":41,"code":671,"language":43,"meta":44,"style":44},"\u002F\u002F run 1\nconst project = axon.thread(\"project-alpha\")\nawait project.request(\"what are the tradeoffs of a document vs relational schema?\")\n\n\u002F\u002F run 2 — next day\nconst project = axon.thread(\"project-alpha\")\nawait project.request(\"what did we decide about the schema?\")\n\u002F\u002F agent sees everything from run 1\n",[18,673,674,679,701,718,722,727,747,764],{"__ignoreMap":44},[48,675,676],{"class":50,"line":51},[48,677,678],{"class":117},"\u002F\u002F run 1\n",[48,680,681,683,686,688,690,692,694,696,699],{"class":50,"line":91},[48,682,55],{"class":54},[48,684,685],{"class":58}," project",[48,687,63],{"class":62},[48,689,399],{"class":70},[48,691,74],{"class":62},[48,693,36],{"class":77},[48,695,81],{"class":62},[48,697,698],{"class":84},"\"project-alpha\"",[48,700,88],{"class":62},[48,702,703,705,707,709,711,713,716],{"class":50,"line":121},[48,704,67],{"class":66},[48,706,685],{"class":70},[48,708,74],{"class":62},[48,710,78],{"class":77},[48,712,81],{"class":62},[48,714,715],{"class":84},"\"what are the tradeoffs of a document vs relational schema?\"",[48,717,88],{"class":62},[48,719,720],{"class":50,"line":215},[48,721,192],{"emptyLinePlaceholder":191},[48,723,724],{"class":50,"line":227},[48,725,726],{"class":117},"\u002F\u002F run 2 — next day\n",[48,728,729,731,733,735,737,739,741,743,745],{"class":50,"line":238},[48,730,55],{"class":54},[48,732,685],{"class":58},[48,734,63],{"class":62},[48,736,399],{"class":70},[48,738,74],{"class":62},[48,740,36],{"class":77},[48,742,81],{"class":62},[48,744,698],{"class":84},[48,746,88],{"class":62},[48,748,749,751,753,755,757,759,762],{"class":50,"line":244},[48,750,67],{"class":66},[48,752,685],{"class":70},[48,754,74],{"class":62},[48,756,78],{"class":77},[48,758,81],{"class":62},[48,760,761],{"class":84},"\"what did we decide about the schema?\"",[48,763,88],{"class":62},[48,765,766],{"class":50,"line":249},[48,767,768],{"class":117},"\u002F\u002F agent sees everything from run 1\n",[14,770,771],{},"This makes named threads useful as durable scratchpads for ongoing work — decisions,\nresearch, plans that accumulate across multiple invocations of the same script.",[773,774,775],"style",{},"html pre.shiki code .scz_3, html code.shiki .scz_3{--shiki-default:#569CD6}html pre.shiki code .s9McN, html code.shiki .s9McN{--shiki-default:#4FC1FF}html pre.shiki code .sTNBD, html code.shiki .sTNBD{--shiki-default:#D4D4D4}html pre.shiki code .sYbnZ, html code.shiki .sYbnZ{--shiki-default:#C586C0}html pre.shiki code .s3F5K, html code.shiki .s3F5K{--shiki-default:#9CDCFE}html pre.shiki code .sCudf, html code.shiki .sCudf{--shiki-default:#DCDCAA}html pre.shiki code .sKc5r, html code.shiki .sKc5r{--shiki-default:#CE9178}html pre.shiki code .sOLPB, html code.shiki .sOLPB{--shiki-default:#6A9955}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sNl3T, html code.shiki .sNl3T{--shiki-default:#4EC9B0}html pre.shiki code .svVle, html code.shiki .svVle{--shiki-default:#D7BA7D}",{"title":44,"searchDepth":91,"depth":91,"links":777},[778,779,780,781,782],{"id":29,"depth":91,"text":30},{"id":153,"depth":91,"text":154},{"id":368,"depth":91,"text":369},{"id":494,"depth":91,"text":495},{"id":664,"depth":91,"text":665},"Every axon.request and axon.stream call runs inside a thread. A thread is a\nconversation history — the agent sees all prior entries when you continue it.","md",{},"\u002Fdocs\u002Fv2\u002Fapi\u002Fthread",{"title":5,"description":783},"docs\u002Fv2\u002Fapi\u002Fthread","JmmKWv1b-QYhZHw6J5Ej_4lka1Cojt31Yc3o513xj0M",1785671808423]