-// modelClient sends model calls.
-type modelClient interface {
- Create(ctx context.Context, request Request) (Response, error)
-}
-
-// Event tells the clients what the agent does as it happens. Kind is the kind
-// of a logged message (user, reply, tool, echo), or one of busy, idle, and
-// error. ID is the ID of a logged message.
-type Event struct {
- Kind string `json:"kind"`
- ID int `json:"id,omitempty"`
- Text string `json:"text,omitempty"`
-}
-
-// loop runs the turns of one agent. A user message goes to the log when it
-// comes, and it wakes the loop. A turn waits until every message before it is
-// summarized. Then its first request holds the prompt, the tools, and the
-// input of turnInput. The loop runs the tool calls of each response and sends
-// their results back, until a response has no tool call: the final answer.
-//
-// The view goes out as the messages of a viewLayout, so the first request of
-// a turn reads the view of the turn before from the prompt cache.
-//
-// Each later request of a turn begins with the whole input of the request
-// before it, then its output items, then the tool results. The output items
-// hold the reasoning with its encrypted content, because the calls do not
-// store it. So each request begins with all of the previous one and reads it
-// from the prompt cache. User messages that come during a turn join the next
-// request after the tool results. The replies, the tool calls, and the results
-// go to the log as they happen. The thoughts never do.
-type loop struct {
- agent *Agent
- memory *Memory
- client modelClient
- tools *toolbox
- layout *viewLayout
- clock func() time.Time
- notify func(Event)
- wake chan struct{}
-
- mutex sync.Mutex
- pending []Message
- cancel context.CancelFunc
-}
-
-// functionCall holds the fields of a function call output item.
-type functionCall struct {
- Type string `json:"type"`
- Name string `json:"name"`
- Arguments string `json:"arguments"`
- CallID string `json:"call_id"`
-}
-
-// functionCallOutput is the input item with the result of a function call.
-type functionCallOutput struct {
- Type string `json:"type"`
- CallID string `json:"call_id"`
- Output string `json:"output"`
-}
-
-// newLoop returns the loop of agent with its memory. Its calls go through