@@ -33,6 +33,14 @@ const returnSchema = z.object({
33
33
. boolean ( )
34
34
. optional ( )
35
35
. describe ( 'Whether the sub-agent was terminated by this message' ) ,
36
+ messageSent : z
37
+ . boolean ( )
38
+ . optional ( )
39
+ . describe ( 'Whether a message was sent to the sub-agent' ) ,
40
+ messageCount : z
41
+ . number ( )
42
+ . optional ( )
43
+ . describe ( "The number of messages in the sub-agent's queue" ) ,
36
44
} ) ;
37
45
38
46
type Parameters = z . infer < typeof parameterSchema > ;
@@ -68,6 +76,8 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
68
76
output : agentState . output || 'Sub-agent was previously terminated' ,
69
77
completed : true ,
70
78
terminated : true ,
79
+ messageSent : false ,
80
+ messageCount : 0 ,
71
81
} ;
72
82
}
73
83
@@ -80,19 +90,24 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
80
90
output : agentState . output || 'Sub-agent terminated before completion' ,
81
91
completed : true ,
82
92
terminated : true ,
93
+ messageSent : false ,
94
+ messageCount : 0 ,
83
95
} ;
84
96
}
85
97
86
- // Add guidance to the agent state for future implementation
87
- // In a more advanced implementation, this could inject the guidance
88
- // into the agent's execution context
98
+ // Add guidance to the agent state's parentMessages array
99
+ // The sub-agent will check for these messages on each iteration
89
100
if ( guidance ) {
90
101
logger . info (
91
102
`Guidance provided to sub-agent ${ instanceId } : ${ guidance } ` ,
92
103
) ;
93
- // This is a placeholder for future implementation
94
- // In a real implementation, we would need to interrupt the agent's
95
- // execution and inject this guidance
104
+
105
+ // Add the guidance to the parentMessages array
106
+ agentState . parentMessages . push ( guidance ) ;
107
+
108
+ logger . verbose (
109
+ `Added message to sub-agent ${ instanceId } 's parentMessages queue. Total messages: ${ agentState . parentMessages . length } ` ,
110
+ ) ;
96
111
}
97
112
98
113
// Get the current output
@@ -103,6 +118,8 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
103
118
output,
104
119
completed : agentState . completed ,
105
120
...( agentState . error && { error : agentState . error } ) ,
121
+ messageSent : guidance ? true : false ,
122
+ messageCount : agentState . parentMessages . length ,
106
123
} ;
107
124
} catch ( error ) {
108
125
if ( error instanceof Error ) {
@@ -112,6 +129,8 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
112
129
output : '' ,
113
130
completed : false ,
114
131
error : error . message ,
132
+ messageSent : false ,
133
+ messageCount : 0 ,
115
134
} ;
116
135
}
117
136
@@ -123,6 +142,8 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
123
142
output : '' ,
124
143
completed : false ,
125
144
error : `Unknown error occurred: ${ errorMessage } ` ,
145
+ messageSent : false ,
146
+ messageCount : 0 ,
126
147
} ;
127
148
}
128
149
} ,
@@ -142,5 +163,11 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
142
163
} else {
143
164
logger . info ( 'Sub-agent is still running' ) ;
144
165
}
166
+
167
+ if ( output . messageSent ) {
168
+ logger . info (
169
+ `Message sent to sub-agent. Queue now has ${ output . messageCount || 0 } message(s).` ,
170
+ ) ;
171
+ }
145
172
} ,
146
173
} ;
0 commit comments