Documentation
¶
Overview ¶
Package core provides the central agent logic, tool management, and ReAct loop implementation for the Falcon API debugging assistant.
Package core provides the central agent logic, tool management, and ReAct loop implementation for the Falcon API debugging assistant.
Index ¶
- Constants
- Variables
- func EnsureGlobalFalconDir() error
- func GetActiveProviderEntry(cfg *GlobalConfig) (providerID, model string, values map[string]string)
- func GetConfigFramework() string
- func GlobalConfigPath() string
- func GlobalFalconDir() string
- func InitializeFalconFolder(framework string, skipIndex bool) error
- func RunGlobalConfigWizard() error
- func SaveGlobalConfig(cfg *GlobalConfig) error
- func SetProviderEntry(cfg *GlobalConfig, providerID, model string, values map[string]string)
- type Agent
- func (a *Agent) AppendHistory(msg llm.Message)
- func (a *Agent) AppendHistoryPair(assistantMsg, observationMsg llm.Message)
- func (a *Agent) ExecuteTool(toolName string, args string) (string, error)
- func (a *Agent) GetFramework() string
- func (a *Agent) GetHistory() []llm.Message
- func (a *Agent) GetPromptTokenEstimate() int
- func (a *Agent) LLMClient() llm.LLMClient
- func (a *Agent) ProcessMessage(input string) (string, error)
- func (a *Agent) ProcessMessageWithEvents(ctx context.Context, input string, callback EventCallback) (string, error)
- func (a *Agent) RegisterTool(tool Tool)
- func (a *Agent) SetFramework(framework string)
- func (a *Agent) SetLastResponse(response interface{})
- func (a *Agent) SetMaxHistory(max int)
- func (a *Agent) SetMemoryStore(store *MemoryStore)
- func (a *Agent) SwapLLMClient(client llm.LLMClient)
- type AgentEvent
- type Config
- type ConfirmableTool
- type ErrorContext
- type EventCallback
- type FileConfirmation
- type GeminiConfig
- type GlobalConfig
- type MemoryEntry
- type MemoryStore
- func (ms *MemoryStore) FalconDir() string
- func (ms *MemoryStore) Forget(key string) error
- func (ms *MemoryStore) GetCompactSummary() string
- func (ms *MemoryStore) List() []MemoryEntry
- func (ms *MemoryStore) ListByCategory(category string) []MemoryEntry
- func (ms *MemoryStore) Recall(query string) []MemoryEntry
- func (ms *MemoryStore) Save(key, value, category string) error
- func (ms *MemoryStore) UpdateKnowledge(section, newContent string) error
- type OllamaConfig
- type OpenRouterConfig
- type ProviderEntry
- type SetupResult
- type StackFrame
- type Tool
Constants ¶
const (
DefaultMaxHistory = 100 // Default max messages to keep in history
)
Default limits for history management.
const FalconFolderName = ".falcon"
Variables ¶
var ErrSetupCancelled = errors.New("setup cancelled by user")
ErrSetupCancelled is returned when the user cancels the setup wizard.
var SupportedFrameworks = []string{
"gin",
"echo",
"chi",
"fiber",
"fastapi",
"flask",
"django",
"express",
"nestjs",
"hono",
"spring",
"laravel",
"rails",
"actix",
"axum",
"other",
}
SupportedFrameworks lists frameworks that Falcon recognizes
Functions ¶
func EnsureGlobalFalconDir ¶
func EnsureGlobalFalconDir() error
EnsureGlobalFalconDir creates ~/.falcon if it doesn't exist (with 0700 permissions) and ensures memory.json exists with an empty valid structure.
func GetActiveProviderEntry ¶
func GetActiveProviderEntry(cfg *GlobalConfig) (providerID, model string, values map[string]string)
GetActiveProviderEntry returns the ID, model, and config values for the currently active (default) provider. Returns empty strings/nil if nothing configured.
func GetConfigFramework ¶
func GetConfigFramework() string
GetConfigFramework reads the framework from the config file
func GlobalConfigPath ¶
func GlobalConfigPath() string
GlobalConfigPath returns the path to the global config file.
func GlobalFalconDir ¶
func GlobalFalconDir() string
GlobalFalconDir returns the path to the global ~/.falcon directory.
func InitializeFalconFolder ¶
InitializeFalconFolder creates the .falcon directory and initializes default files if they don't exist. If framework is empty and this is a first-time setup, prompts the user to select one. skipIndex determines if we should auto-run the spec ingester.
func RunGlobalConfigWizard ¶
func RunGlobalConfigWizard() error
RunGlobalConfigWizard runs the interactive provider/model setup wizard and saves to global config. Presents a sub-action menu: add/update a provider, set default provider, or remove a provider.
func SaveGlobalConfig ¶
func SaveGlobalConfig(cfg *GlobalConfig) error
SaveGlobalConfig writes the GlobalConfig to ~/.falcon/config.yaml (0600 perms).
func SetProviderEntry ¶
func SetProviderEntry(cfg *GlobalConfig, providerID, model string, values map[string]string)
SetProviderEntry upserts a provider entry into the config without touching any other provider entries.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent represents the Falcon AI agent that processes user messages, executes tools, and provides API debugging assistance.
func (*Agent) AppendHistory ¶
AppendHistory adds a message to the history and truncates if necessary. When maxHistory is reached, older messages are removed to make room. The truncation keeps the most recent messages while preserving context. This method is thread-safe.
func (*Agent) AppendHistoryPair ¶
AppendHistoryPair adds an assistant message and observation to history atomically. This ensures tool call and observation stay together during truncation. This method is thread-safe.
func (*Agent) ExecuteTool ¶
ExecuteTool executes a tool by name (used by retry tool). This method is thread-safe for looking up the tool.
func (*Agent) GetFramework ¶
GetFramework returns the configured API framework.
func (*Agent) GetHistory ¶
GetHistory returns a copy of the agent's conversation history. This method is thread-safe.
func (*Agent) GetPromptTokenEstimate ¶
GetPromptTokenEstimate returns an estimate of how many tokens the system prompt uses.
func (*Agent) ProcessMessage ¶
ProcessMessage handles a user message using ReAct logic. It runs the think-act-observe cycle until a final answer is reached. This is the blocking version without events.
func (*Agent) ProcessMessageWithEvents ¶
func (a *Agent) ProcessMessageWithEvents(ctx context.Context, input string, callback EventCallback) (string, error)
ProcessMessageWithEvents handles a user message and emits events for each stage. This enables real-time UI updates as the agent thinks, uses tools, and responds. Events emitted: thinking, tool_call, observation, answer, error, streaming, confirmation_required The context can be used to cancel the agent mid-processing.
func (*Agent) RegisterTool ¶
RegisterTool adds a tool to the agent's arsenal. This method is thread-safe.
func (*Agent) SetFramework ¶
SetFramework sets the user's API framework for context-aware assistance. Supported frameworks include: gin, echo, chi, fiber, fastapi, flask, django, express, nestjs, hono, spring, laravel, rails, actix, axum, other.
func (*Agent) SetLastResponse ¶
func (a *Agent) SetLastResponse(response interface{})
SetLastResponse stores the last response from a tool for chaining.
func (*Agent) SetMaxHistory ¶
SetMaxHistory sets the maximum number of messages to keep in history. Set to 0 for unlimited history (not recommended for long sessions).
func (*Agent) SetMemoryStore ¶
func (a *Agent) SetMemoryStore(store *MemoryStore)
SetMemoryStore sets the persistent memory store for the agent.
func (*Agent) SwapLLMClient ¶
SwapLLMClient replaces the agent's LLM client at runtime.
type AgentEvent ¶
type AgentEvent struct {
// Type indicates the event type: "thinking", "tool_call", "observation",
// "answer", "error", "streaming", "confirmation_required"
Type string
// Content holds the main event payload (varies by type)
Content string
// ToolArgs contains tool arguments (present only for "tool_call" events)
ToolArgs string
// FileConfirmation contains file write info (present only for "confirmation_required" events)
FileConfirmation *FileConfirmation
}
AgentEvent represents a state change during agent processing. Events are emitted via callbacks to enable real-time UI updates.
type Config ¶
type Config struct {
Provider string `yaml:"provider"` // "ollama", "gemini", "openrouter", …
ProviderConfig map[string]string `yaml:"provider_config,omitempty"` // provider-specific key/value pairs
DefaultModel string `yaml:"default_model"`
Theme string `yaml:"theme"`
Framework string `yaml:"framework"` // API framework (e.g., gin, fastapi, express)
// Legacy fields — migrated automatically on first load; do not use in new code.
OllamaConfig *OllamaConfig `yaml:"ollama,omitempty"`
GeminiConfig *GeminiConfig `yaml:"gemini,omitempty"`
OpenRouterConfig *OpenRouterConfig `yaml:"openrouter,omitempty"`
OllamaURL string `yaml:"ollama_url,omitempty"`
OllamaAPIKey string `yaml:"ollama_api_key,omitempty"`
}
Config represents the user's Falcon configuration. Provider-specific settings are stored generically in ProviderConfig so that new providers can be added without changing this struct.
type ConfirmableTool ¶
type ConfirmableTool interface {
Tool
// SetEventCallback sets the callback function for emitting events
SetEventCallback(callback EventCallback)
}
ConfirmableTool is a tool that requires user confirmation before executing. Tools implementing this interface can emit confirmation requests back to the TUI, enabling human-in-the-loop approval for potentially destructive operations.
type ErrorContext ¶
type ErrorContext struct {
Message string `json:"message"` // Main error message
ErrorType string `json:"error_type"` // Type of error (e.g., "ValueError")
StackFrames []StackFrame `json:"stack_frames"` // Parsed stack trace
Details []string `json:"details"` // Additional error details
Fields []string `json:"fields"` // Validation error fields
}
ErrorContext contains extracted error information from a response.
func ExtractErrorContext ¶
func ExtractErrorContext(body string, statusCode int) *ErrorContext
ExtractErrorContext extracts error information from an HTTP response body
func (*ErrorContext) FormatErrorContext ¶
func (ctx *ErrorContext) FormatErrorContext() string
FormatErrorContext returns a human-readable summary of the error context
type EventCallback ¶
type EventCallback func(AgentEvent)
EventCallback is the function signature for agent event handlers. Callbacks receive events as the agent progresses through the ReAct loop.
type FileConfirmation ¶
type FileConfirmation struct {
// FilePath is the path to the file being modified
FilePath string
// IsNewFile is true if creating a new file, false if modifying existing
IsNewFile bool
// Diff is the unified diff showing the proposed changes
Diff string
}
FileConfirmation contains information for file write confirmation prompts. This enables human-in-the-loop approval before any file modifications.
type GeminiConfig ¶
type GeminiConfig struct {
APIKey string `yaml:"api_key"`
}
GeminiConfig holds Gemini-specific configuration (legacy).
type GlobalConfig ¶
type GlobalConfig struct {
DefaultProvider string `yaml:"default_provider"`
Theme string `yaml:"theme"`
Providers map[string]ProviderEntry `yaml:"providers,omitempty"`
// Legacy migration fields — present only in old single-provider configs.
// LoadGlobalConfig migrates them into Providers on first read.
LegacyProvider string `yaml:"provider,omitempty"`
LegacyProviderConfig map[string]string `yaml:"provider_config,omitempty"`
LegacyDefaultModel string `yaml:"default_model,omitempty"`
}
GlobalConfig is the multi-provider global config written to ~/.falcon/config.yaml.
func LoadGlobalConfig ¶
func LoadGlobalConfig() (*GlobalConfig, error)
LoadGlobalConfig reads the global config. If the file doesn't exist, returns a zero-value GlobalConfig with no error. Automatically migrates old single-provider format (top-level provider/provider_config/default_model keys) into the new Providers map on first read.
type MemoryEntry ¶
type MemoryEntry struct {
Key string `json:"key"`
Value string `json:"value"`
Category string `json:"category"` // "preference", "endpoint", "error", "project", "general"
Timestamp string `json:"timestamp"` // RFC3339
Source string `json:"source"` // Session ID that created this
}
MemoryEntry represents a single fact saved by the agent.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore manages persistent agent memory.
func NewMemoryStore ¶
func NewMemoryStore(falconDir string) *MemoryStore
NewMemoryStore creates a MemoryStore and loads existing memory.
func (*MemoryStore) FalconDir ¶
func (ms *MemoryStore) FalconDir() string
FalconDir returns the base .falcon directory path.
func (*MemoryStore) Forget ¶
func (ms *MemoryStore) Forget(key string) error
Forget removes a memory entry by key and persists the change.
func (*MemoryStore) GetCompactSummary ¶
func (ms *MemoryStore) GetCompactSummary() string
GetCompactSummary generates a compact string for injection into the system prompt. Returns empty string if no knowledge base content or memories exist.
func (*MemoryStore) List ¶
func (ms *MemoryStore) List() []MemoryEntry
List returns all memory entries.
func (*MemoryStore) ListByCategory ¶
func (ms *MemoryStore) ListByCategory(category string) []MemoryEntry
ListByCategory returns entries matching the given category.
func (*MemoryStore) Recall ¶
func (ms *MemoryStore) Recall(query string) []MemoryEntry
Recall searches memory entries by substring match across key, value, and category.
func (*MemoryStore) Save ¶
func (ms *MemoryStore) Save(key, value, category string) error
Save upserts a memory entry (updates if key exists, inserts otherwise) and persists to disk. Returns an error if attempting to save secrets to memory.
func (*MemoryStore) UpdateKnowledge ¶
func (ms *MemoryStore) UpdateKnowledge(section, newContent string) error
UpdateKnowledge rewrites a named section in falcon.md with new content. If the section heading does not exist, it is appended. If it exists, the content between that heading and the next H2 heading is replaced.
type OllamaConfig ¶
type OllamaConfig struct {
Mode string `yaml:"mode"` // "local" or "cloud"
URL string `yaml:"url"` // API URL
APIKey string `yaml:"api_key"` // API key (for cloud mode)
}
OllamaConfig holds Ollama-specific configuration (legacy).
type OpenRouterConfig ¶
type OpenRouterConfig struct {
APIKey string `yaml:"api_key"`
}
OpenRouterConfig holds OpenRouter-specific configuration (legacy).
type ProviderEntry ¶
ProviderEntry holds the model and credentials for a single configured provider.
type SetupResult ¶
type SetupResult struct {
Framework string
Provider string
ProviderValues map[string]string // keyed by SetupField.Key
Model string
}
SetupResult holds the values collected by the first-run setup wizard.
type StackFrame ¶
type StackFrame struct {
File string `json:"file"` // File path where error occurred
Line int `json:"line"` // Line number
Function string `json:"function"` // Function name (if available)
Code string `json:"code"` // Source code snippet (optional)
}
StackFrame represents a single frame in a stack trace.
func ParseStackTrace ¶
func ParseStackTrace(text string) []StackFrame
ParseStackTrace extracts stack frames from various stack trace formats
type Tool ¶
type Tool interface {
// Name returns the unique identifier for this tool.
Name() string
// Description returns a human-readable description of what this tool does.
Description() string
// Parameters returns a description of the JSON parameters this tool accepts.
Parameters() string
// Execute runs the tool with the given JSON arguments and returns the result.
Execute(args string) (string, error)
}
Tool represents an agent capability that can be executed. Each tool has a name, description, parameters schema, and execution logic. Tools are registered with the Agent and can be invoked during the ReAct loop.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
agent
Package agent provides agent memory and reporting tools for ZAP.
|
Package agent provides agent memory and reporting tools for ZAP. |
|
data_driven_engine
Package data_driven_engine provides template-based parameterized test execution for ZAP.
|
Package data_driven_engine provides template-based parameterized test execution for ZAP. |
|
debugging
Package debugging provides debugging and codebase analysis tools for ZAP.
|
Package debugging provides debugging and codebase analysis tools for ZAP. |
|
functional_test_generator
Package functional_test_generator provides spec-driven functional test generation for ZAP.
|
Package functional_test_generator provides spec-driven functional test generation for ZAP. |
|
idempotency_verifier
Package idempotency_verifier provides idempotency validation for API endpoints for ZAP.
|
Package idempotency_verifier provides idempotency validation for API endpoints for ZAP. |
|
integration_orchestrator
Package integration_orchestrator provides multi-step integration test workflows for ZAP.
|
Package integration_orchestrator provides multi-step integration test workflows for ZAP. |
|
performance_engine
Package performance_engine provides multi-mode performance and load testing for ZAP.
|
Package performance_engine provides multi-mode performance and load testing for ZAP. |
|
persistence
Package persistence provides request persistence and environment management tools for ZAP.
|
Package persistence provides request persistence and environment management tools for ZAP. |
|
regression_watchdog
Package regression_watchdog provides baseline comparison and regression detection for ZAP.
|
Package regression_watchdog provides baseline comparison and regression detection for ZAP. |
|
security_scanner
Package security_scanner provides OWASP security scanning and vulnerability detection for ZAP.
|
Package security_scanner provides OWASP security scanning and vulnerability detection for ZAP. |
|
shared
Package shared provides merged authentication tools for the Falcon agent.
|
Package shared provides merged authentication tools for the Falcon agent. |
|
smoke_runner
Package smoke_runner provides lightweight deployment health checks for ZAP.
|
Package smoke_runner provides lightweight deployment health checks for ZAP. |
|
spec_ingester
Package spec_ingester provides API specification parsing and knowledge graph building for ZAP.
|
Package spec_ingester provides API specification parsing and knowledge graph building for ZAP. |