Send appends a user message and runs the tool-use loop until the model stops requesting tools (or MaxTurns is reached). Returns the final assistant text concatenation, which is printed live as it arrives for the root agent and silently accumulated for subagents.
(ctx context.Context, prompt string)
| 61 | // assistant text concatenation, which is printed live as it arrives for |
| 62 | // the root agent and silently accumulated for subagents. |
| 63 | func (a *Agent) Send(ctx context.Context, prompt string) (string, error) { |
| 64 | a.messages = append(a.messages, api.Message{ |
| 65 | Role: api.RoleUser, |
| 66 | Content: []api.Block{{Type: api.BlockText, Text: prompt}}, |
| 67 | }) |
| 68 | return a.loop(ctx) |
| 69 | } |
| 70 | |
| 71 | func (a *Agent) loop(ctx context.Context) (string, error) { |
| 72 | var finalText strings.Builder |