@@ -4,8 +4,10 @@ use serde_json::json;
44use tokio:: sync:: { watch, Semaphore } ;
55use tokio:: task:: JoinSet ;
66
7+ use crate :: builtin;
78use crate :: config:: { Config , MAX_PROMPT_BYTES , MAX_TOOL_CALLS_PER_TURN , MAX_TOOL_RESULT_BYTES } ;
89use crate :: handoff:: HandoffOutcome ;
10+ use crate :: hints:: SkillEntry ;
911use crate :: llm:: Llm ;
1012use crate :: mcp:: McpRegistry ;
1113use crate :: mcp:: ResultBudget ;
@@ -25,6 +27,8 @@ pub struct RunCtx<'a> {
2527 pub system_prompt : & ' a str ,
2628 pub llm : & ' a Llm ,
2729 pub mcp : & ' a Arc < McpRegistry > ,
30+ /// Skills discovered at session creation; used by the built-in `load_skill` tool.
31+ pub skills : & ' a [ SkillEntry ] ,
2832 pub wire : & ' a WireSender ,
2933 pub cancel : & ' a mut watch:: Receiver < bool > ,
3034 pub history : & ' a mut Vec < HistoryItem > ,
@@ -90,7 +94,11 @@ impl RunCtx<'_> {
9094 }
9195 }
9296
93- let tools = self . mcp . tools ( ) ;
97+ let mut tools = self . mcp . tools ( ) ;
98+ // Inject the built-in load_skill tool when skills are available.
99+ if !self . skills . is_empty ( ) {
100+ tools. push ( builtin:: load_skill_def ( ) ) ;
101+ }
94102 round = round. saturating_add ( 1 ) ;
95103 let response = tokio:: select! {
96104 biased;
@@ -246,6 +254,17 @@ impl RunCtx<'_> {
246254 return Some ( StopReason :: Cancelled ) ;
247255 }
248256 emit_pending ( self . wire , self . session_id , call) . await ;
257+
258+ // Built-in load_skill: execute inline, no MCP round-trip.
259+ if call. name == builtin:: LOAD_SKILL_TOOL {
260+ emit_in_progress ( self . wire , self . session_id , call) . await ;
261+ let mut result = builtin:: call_load_skill ( & call. arguments , self . skills ) . await ;
262+ result. provider_id = call. provider_id . clone ( ) ;
263+ emit_completed ( self . wire , self . session_id , call, & result) . await ;
264+ results[ idx] = Some ( result) ;
265+ continue ;
266+ }
267+
249268 // Hook tools (bare name starts with `_`) are invisible to the
250269 // LLM and only callable via `call_hooks`. Treat any direct
251270 // invocation as if the tool didn't exist.
0 commit comments