Documentation
¶
Overview ¶
Package async provides examples of async tool implementations.
Package async provides advanced async tool execution patterns for the ADK framework.
Index ¶
- Variables
- type AsyncTool
- type BaseToolImpl
- type FileProcessorTool
- type StreamingTool
- func (t *StreamingTool) CanCancel() bool
- func (t *StreamingTool) Cancel(ctx context.Context, toolID string) error
- func (t *StreamingTool) GetStatus(ctx context.Context, toolID string) (*ToolProgress, error)
- func (t *StreamingTool) ProcessLLMRequest(ctx context.Context, toolCtx *core.ToolContext, request *core.LLMRequest) error
- func (t *StreamingTool) RunAsync(ctx context.Context, args map[string]any, toolCtx *core.ToolContext) (any, error)
- func (t *StreamingTool) RunStream(ctx context.Context, args map[string]any, toolCtx *core.ToolContext) (*ToolStream, error)
- func (t *StreamingTool) SetExecuteFunc(...)
- type ToolProgress
- type ToolResult
- type ToolStream
- type WebScraperTool
Constants ¶
This section is empty.
Variables ¶
var ( ErrTooManyActiveTasks = fmt.Errorf("too many active tool executions") ErrToolNotFound = fmt.Errorf("tool execution not found") )
Functions ¶
This section is empty.
Types ¶
type AsyncTool ¶
type AsyncTool interface {
core.BaseTool
// RunStream executes the tool and returns a stream of progress updates and final result.
// This is the preferred method for long-running operations.
RunStream(ctx context.Context, args map[string]any, toolCtx *core.ToolContext) (*ToolStream, error)
// CanCancel indicates if the tool supports cancellation during execution.
CanCancel() bool
// Cancel cancels a running tool execution by ID.
Cancel(ctx context.Context, toolID string) error
// GetStatus returns the current status of a running tool execution.
GetStatus(ctx context.Context, toolID string) (*ToolProgress, error)
}
AsyncTool extends BaseTool with advanced async capabilities.
type BaseToolImpl ¶
type BaseToolImpl struct {
// contains filtered or unexported fields
}
BaseToolImpl wraps the original BaseToolImpl to avoid import cycles.
func (*BaseToolImpl) Description ¶
func (t *BaseToolImpl) Description() string
Description returns a description of the tool's purpose.
func (*BaseToolImpl) GetDeclaration ¶
func (t *BaseToolImpl) GetDeclaration() *core.FunctionDeclaration
GetDeclaration returns the function declaration for LLM integration.
func (*BaseToolImpl) IsLongRunning ¶
func (t *BaseToolImpl) IsLongRunning() bool
IsLongRunning indicates if this is a long-running operation.
func (*BaseToolImpl) Name ¶
func (t *BaseToolImpl) Name() string
Name returns the tool's unique identifier.
type FileProcessorTool ¶
type FileProcessorTool struct {
*StreamingTool
}
FileProcessorTool demonstrates a long-running file processing tool.
func NewFileProcessorTool ¶
func NewFileProcessorTool() *FileProcessorTool
NewFileProcessorTool creates a new file processor tool.
func (*FileProcessorTool) GetDeclaration ¶
func (t *FileProcessorTool) GetDeclaration() *core.FunctionDeclaration
GetDeclaration returns the function declaration for LLM integration.
type StreamingTool ¶
type StreamingTool struct {
*BaseToolImpl
// contains filtered or unexported fields
}
StreamingTool provides a base implementation for streaming tools.
func NewStreamingTool ¶
func NewStreamingTool(name, description string, maxConcurrency int) *StreamingTool
NewStreamingTool creates a new streaming tool with the specified concurrency limit.
func (*StreamingTool) CanCancel ¶
func (t *StreamingTool) CanCancel() bool
CanCancel indicates if the tool supports cancellation.
func (*StreamingTool) Cancel ¶
func (t *StreamingTool) Cancel(ctx context.Context, toolID string) error
Cancel cancels a running tool execution by ID.
func (*StreamingTool) GetStatus ¶
func (t *StreamingTool) GetStatus(ctx context.Context, toolID string) (*ToolProgress, error)
GetStatus returns the current status of a running tool execution.
func (*StreamingTool) ProcessLLMRequest ¶
func (t *StreamingTool) ProcessLLMRequest(ctx context.Context, toolCtx *core.ToolContext, request *core.LLMRequest) error
ProcessLLMRequest allows the tool to modify LLM requests.
func (*StreamingTool) RunAsync ¶
func (t *StreamingTool) RunAsync(ctx context.Context, args map[string]any, toolCtx *core.ToolContext) (any, error)
RunAsync implements BaseTool interface by calling RunStream and waiting for result.
func (*StreamingTool) RunStream ¶
func (t *StreamingTool) RunStream(ctx context.Context, args map[string]any, toolCtx *core.ToolContext) (*ToolStream, error)
RunStream executes the tool and returns a stream of progress updates. This is a base implementation that subclasses should override.
func (*StreamingTool) SetExecuteFunc ¶
func (t *StreamingTool) SetExecuteFunc(fn func(context.Context, map[string]any, *core.ToolContext, chan<- *ToolProgress, string) (any, error))
SetExecuteFunc allows setting a custom execution function.
type ToolProgress ¶
type ToolProgress struct {
ID string `json:"id"`
Progress float64 `json:"progress"` // 0.0 to 1.0
Message string `json:"message"` // Human-readable status
Metadata map[string]any `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
Cancelable bool `json:"cancelable"`
}
ToolProgress represents progress updates from a long-running tool.
type ToolResult ¶
type ToolResult struct {
Result any `json:"result,omitempty"`
Error error `json:"error,omitempty"`
Done bool `json:"done"`
ID string `json:"id"`
}
ToolResult represents the result of an async tool execution.
type ToolStream ¶
type ToolStream struct {
Progress <-chan *ToolProgress `json:"-"`
Result <-chan *ToolResult `json:"-"`
Cancel context.CancelFunc `json:"-"`
}
ToolStream represents a stream of progress updates and final result.
type WebScraperTool ¶
type WebScraperTool struct {
*StreamingTool
// contains filtered or unexported fields
}
WebScraperTool demonstrates another async tool with different characteristics.
func NewWebScraperTool ¶
func NewWebScraperTool() *WebScraperTool
NewWebScraperTool creates a new web scraper tool.
func (*WebScraperTool) GetDeclaration ¶
func (t *WebScraperTool) GetDeclaration() *core.FunctionDeclaration
GetDeclaration returns the function declaration for LLM integration.