giagentcore

package
v0.82.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ToolExecutionSequential = "sequential"
	ToolExecutionParallel   = "parallel"

	QueueAll       = "all"
	QueueOneAtTime = "one-at-a-time"
)

Variables

This section is empty.

Functions

func AgentLoop

func AgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, ctx context.Context, streamFn StreamFn) *llm.EventStream[AgentEvent, []llm.Message]

func AgentLoopContinue

func AgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, ctx context.Context, streamFn StreamFn) (*llm.EventStream[AgentEvent, []llm.Message], error)

func RunAgentLoop

func RunAgentLoop(prompts []llm.Message, agentContext AgentContext, config AgentLoopConfig, emit AgentEventSink, ctx context.Context, streamFn StreamFn) ([]llm.Message, error)

func RunAgentLoopContinue

func RunAgentLoopContinue(agentContext AgentContext, config AgentLoopConfig, emit AgentEventSink, ctx context.Context, streamFn StreamFn) ([]llm.Message, error)

func SetDefaultStreamFn added in v0.82.0

func SetDefaultStreamFn(streamFn StreamFn)

SetDefaultStreamFn configures the fallback used when an Agent or low-level loop caller omits its stream function. Passing nil clears the fallback.

func StreamProxy

func StreamProxy(model llm.Model, llmContext llm.Context, options ProxyStreamOptions) *llm.AssistantMessageEventStream

Types

type AfterToolCallContext

type AfterToolCallContext struct {
	AssistantMessage llm.Message
	ToolCall         AgentToolCall
	Args             map[string]any
	Result           AgentToolResult
	IsError          bool
	Context          AgentContext
}

type AfterToolCallResult

type AfterToolCallResult struct {
	Content      []llm.ContentPart
	HasContent   bool
	Details      any
	HasDetails   bool
	IsError      bool
	HasIsError   bool
	Terminate    bool
	HasTerminate bool
}

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

func New

func New(options ...AgentOption) *Agent

func NewAgent

func NewAgent(options AgentOptions) *Agent

func (*Agent) Abort

func (a *Agent) Abort()

func (*Agent) ClearAllQueues

func (a *Agent) ClearAllQueues()

func (*Agent) ClearFollowUpQueue

func (a *Agent) ClearFollowUpQueue()

func (*Agent) ClearSteeringQueue

func (a *Agent) ClearSteeringQueue()

func (*Agent) Continue

func (a *Agent) Continue(ctx context.Context) error

func (*Agent) FollowUp

func (a *Agent) FollowUp(message llm.Message)

func (*Agent) FollowUpMode

func (a *Agent) FollowUpMode() string

func (*Agent) HasQueuedMessages

func (a *Agent) HasQueuedMessages() bool

func (*Agent) Prompt

func (a *Agent) Prompt(ctx context.Context, messages ...llm.Message) error

func (*Agent) PromptText

func (a *Agent) PromptText(ctx context.Context, text string, images ...llm.ContentPart) error

func (*Agent) Reset

func (a *Agent) Reset()

func (*Agent) SetFollowUpMode

func (a *Agent) SetFollowUpMode(mode string)

func (*Agent) SetMessages

func (a *Agent) SetMessages(messages []llm.Message)

func (*Agent) SetModel

func (a *Agent) SetModel(model llm.Model)

func (*Agent) SetSteeringMode

func (a *Agent) SetSteeringMode(mode string)

func (*Agent) SetSystemPrompt

func (a *Agent) SetSystemPrompt(prompt string)

func (*Agent) SetThinkingLevel

func (a *Agent) SetThinkingLevel(level string)

func (*Agent) SetTools

func (a *Agent) SetTools(tools []AgentTool)

func (*Agent) State

func (a *Agent) State() AgentState

func (*Agent) Steer

func (a *Agent) Steer(message llm.Message)

func (*Agent) SteeringMode

func (a *Agent) SteeringMode() string

func (*Agent) Subscribe

func (a *Agent) Subscribe(listener func(AgentEvent, context.Context) error) func()

func (*Agent) WaitForIdle

func (a *Agent) WaitForIdle(ctx context.Context) error

type AgentContext

type AgentContext struct {
	SystemPrompt string
	Messages     []llm.Message
	Tools        []AgentTool
}

type AgentEvent

type AgentEvent struct {
	Type                  string
	Messages              []llm.Message
	Message               llm.Message
	ToolResults           []llm.Message
	AssistantMessageEvent llm.AssistantMessageEvent
	ToolCallID            string
	ToolName              string
	Args                  map[string]any
	PartialResult         any
	Result                any
	IsError               bool
}

type AgentEventSink

type AgentEventSink func(event AgentEvent) error

type AgentLoopConfig

type AgentLoopConfig struct {
	llm.SimpleStreamOptions
	Model llm.Model

	ConvertToLLM     func(messages []llm.Message) ([]llm.Message, error)
	TransformContext func(ctx context.Context, messages []llm.Message) ([]llm.Message, error)
	GetAPIKey        func(provider string) string

	ShouldStopAfterTurn func(ShouldStopAfterTurnContext) (bool, error)
	PrepareNextTurn     func(PrepareNextTurnContext) (AgentLoopTurnUpdate, bool, error)
	GetSteeringMessages func() ([]llm.Message, error)
	GetFollowUpMessages func() ([]llm.Message, error)

	ToolExecution  string
	BeforeToolCall func(context.Context, BeforeToolCallContext) (BeforeToolCallResult, error)
	AfterToolCall  func(context.Context, AfterToolCallContext) (AfterToolCallResult, error)
}

type AgentLoopTurnUpdate

type AgentLoopTurnUpdate struct {
	Context       *AgentContext
	Model         *llm.Model
	ThinkingLevel *string
}

type AgentMessage

type AgentMessage = llm.Message

type AgentOption

type AgentOption func(*AgentOptions)

func WithConvertToLLM

func WithConvertToLLM(convert func(messages []llm.Message) ([]llm.Message, error)) AgentOption

func WithInitialState

func WithInitialState(state AgentState) AgentOption

func WithSession

func WithSession(id string) AgentOption

func WithStreamFn

func WithStreamFn(streamFn StreamFn) AgentOption

func WithToolExecution

func WithToolExecution(mode string) AgentOption

func WithTransformContext

func WithTransformContext(transform func(ctx context.Context, messages []llm.Message) ([]llm.Message, error)) AgentOption

type AgentOptions

type AgentOptions struct {
	InitialState     AgentState
	ConvertToLLM     func(messages []llm.Message) ([]llm.Message, error)
	TransformContext func(ctx context.Context, messages []llm.Message) ([]llm.Message, error)
	StreamFn         StreamFn
	GetAPIKey        func(provider string) string
	BeforeToolCall   func(context.Context, BeforeToolCallContext) (BeforeToolCallResult, error)
	AfterToolCall    func(context.Context, AfterToolCallContext) (AfterToolCallResult, error)
	PrepareNextTurn  func(context.Context) (AgentLoopTurnUpdate, bool, error)
	SteeringMode     string
	FollowUpMode     string
	SessionID        string
	ThinkingBudgets  map[string]int
	Transport        string
	MaxRetryDelayMs  int
	ToolExecution    string
}

type AgentState

type AgentState struct {
	SystemPrompt     string
	Model            llm.Model
	ThinkingLevel    string
	Tools            []AgentTool
	Messages         []llm.Message
	IsStreaming      bool
	StreamingMessage *llm.Message
	PendingToolCalls map[string]bool
	ErrorMessage     string
}

type AgentTool

type AgentTool struct {
	Name        string
	Label       string
	Description string
	Parameters  llm.Schema

	PrepareArguments func(args any) (map[string]any, error)
	Execute          func(ctx context.Context, toolCallID string, params map[string]any, onUpdate AgentToolUpdateCallback) (AgentToolResult, error)
	ExecutionMode    string
}

func (AgentTool) AsLLMTool

func (t AgentTool) AsLLMTool() llm.Tool

type AgentToolCall

type AgentToolCall = llm.ContentPart

type AgentToolResult

type AgentToolResult struct {
	Content   []llm.ContentPart
	Details   any
	Terminate bool
}

type AgentToolUpdateCallback

type AgentToolUpdateCallback func(partialResult AgentToolResult)

type BeforeToolCallContext

type BeforeToolCallContext struct {
	AssistantMessage llm.Message
	ToolCall         AgentToolCall
	Args             map[string]any
	Context          AgentContext
}

type BeforeToolCallResult

type BeforeToolCallResult struct {
	Block  bool
	Reason string
}

type PrepareNextTurnContext

type PrepareNextTurnContext = ShouldStopAfterTurnContext

type ProxyAssistantMessageEvent

type ProxyAssistantMessageEvent struct {
	Type             string    `json:"type"`
	ContentIndex     int       `json:"contentIndex,omitempty"`
	Delta            string    `json:"delta,omitempty"`
	ContentSignature string    `json:"contentSignature,omitempty"`
	ID               string    `json:"id,omitempty"`
	ToolName         string    `json:"toolName,omitempty"`
	Reason           string    `json:"reason,omitempty"`
	ErrorMessage     string    `json:"errorMessage,omitempty"`
	Usage            llm.Usage `json:"usage,omitempty"`
}

type ProxyStreamOptions

type ProxyStreamOptions struct {
	llm.SimpleStreamOptions
	AuthToken  string
	ProxyURL   string
	HTTPClient *http.Client
}

type ShouldStopAfterTurnContext

type ShouldStopAfterTurnContext struct {
	Message     llm.Message
	ToolResults []llm.Message
	Context     AgentContext
	NewMessages []llm.Message
}

type StreamFn

type StreamFn func(model llm.Model, llmContext llm.Context, options llm.SimpleStreamOptions) (*llm.AssistantMessageEventStream, error)

func GetDefaultStreamFn added in v0.82.0

func GetDefaultStreamFn() (StreamFn, error)

GetDefaultStreamFn returns the configured fallback stream function.

func NewProxyStreamFn

func NewProxyStreamFn(proxyURL, authToken string, baseOptions llm.SimpleStreamOptions, client *http.Client) StreamFn

Directories

Path Synopsis
env
tools
Package tools provides reusable filesystem and shell tools for AgentHarness.
Package tools provides reusable filesystem and shell tools for AgentHarness.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL