@@ -70,7 +70,12 @@ export namespace Tool {
7070 ? Def < P , M >
7171 : never
7272
73- function wrap < Parameters extends z . ZodType , Result extends Metadata > ( id : string , init : Init < Parameters , Result > ) {
73+ function wrap < Parameters extends z . ZodType , Result extends Metadata > (
74+ id : string ,
75+ init : Init < Parameters , Result > ,
76+ truncate : Truncate . Interface ,
77+ agents : Agent . Interface ,
78+ ) {
7479 return ( ) =>
7580 Effect . gen ( function * ( ) {
7681 const toolInfo = init instanceof Function ? { ...( yield * init ( ) ) } : { ...init }
@@ -93,8 +98,8 @@ export namespace Tool {
9398 if ( result . metadata . truncated !== undefined ) {
9499 return result
95100 }
96- const agent = yield * Effect . promise ( ( ) => Agent . get ( ctx . agent ) )
97- const truncated = yield * Effect . promise ( ( ) => Truncate . output ( result . output , { } , agent ) )
101+ const agent = yield * agents . get ( ctx . agent )
102+ const truncated = yield * truncate . output ( result . output , { } , agent )
98103 return {
99104 ...result ,
100105 output : truncated . content ,
@@ -112,9 +117,14 @@ export namespace Tool {
112117 export function define < Parameters extends z . ZodType , Result extends Metadata , R , ID extends string = string > (
113118 id : ID ,
114119 init : Effect . Effect < Init < Parameters , Result > , never , R > ,
115- ) : Effect . Effect < Info < Parameters , Result > , never , R > & { id : ID } {
120+ ) : Effect . Effect < Info < Parameters , Result > , never , R | Truncate . Service | Agent . Service > & { id : ID } {
116121 return Object . assign (
117- Effect . map ( init , ( init ) => ( { id, init : wrap ( id , init ) } ) ) ,
122+ Effect . gen ( function * ( ) {
123+ const resolved = yield * init
124+ const truncate = yield * Truncate . Service
125+ const agents = yield * Agent . Service
126+ return { id, init : wrap ( id , resolved , truncate , agents ) }
127+ } ) ,
118128 { id } ,
119129 )
120130 }
0 commit comments