mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-06 12:30:59 +08:00
- Add assistant package with AI Agent runtime - agent.go: Core agent loop with tool calling - session.go: Conversation memory management - tool.go: Tool interface and base implementation - trading_tools.go: Trading-specific tools (13 tools) - prompts.go: Trading expert system prompts (EN/ZH) - Add telegram package for Telegram bot integration - bot.go: Telegram bot with rate limiting & access control - config.go: Environment-based configuration - Update main.go to initialize Telegram bot on startup - Update .env.example with new configuration options - Add gopkg.in/telebot.v3 dependency Trading tools available: - Query: get_balance, get_positions, list_traders, get_trader_status - Control: start_trader, stop_trader - Trading: get_market_price, open_long, open_short, close_position - Config: list_strategies, list_exchanges, list_ai_models
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package assistant
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
// Tool represents a callable tool that the AI agent can use
|
|
type Tool interface {
|
|
// Name returns the tool's unique identifier
|
|
Name() string
|
|
|
|
// Description returns a human-readable description for the AI
|
|
Description() string
|
|
|
|
// ParameterSchema returns JSON schema for the tool's parameters
|
|
ParameterSchema() string
|
|
|
|
// Execute runs the tool with the given arguments
|
|
Execute(ctx context.Context, args json.RawMessage) (interface{}, error)
|
|
}
|
|
|
|
// BaseTool provides common functionality for tools
|
|
type BaseTool struct {
|
|
ToolName string
|
|
ToolDescription string
|
|
ToolSchema string
|
|
ExecuteFunc func(ctx context.Context, args json.RawMessage) (interface{}, error)
|
|
}
|
|
|
|
func (t *BaseTool) Name() string { return t.ToolName }
|
|
func (t *BaseTool) Description() string { return t.ToolDescription }
|
|
func (t *BaseTool) ParameterSchema() string { return t.ToolSchema }
|
|
|
|
func (t *BaseTool) Execute(ctx context.Context, args json.RawMessage) (interface{}, error) {
|
|
return t.ExecuteFunc(ctx, args)
|
|
}
|
|
|
|
// NewTool creates a simple tool from a function
|
|
func NewTool(name, description, schema string, fn func(ctx context.Context, args json.RawMessage) (interface{}, error)) Tool {
|
|
return &BaseTool{
|
|
ToolName: name,
|
|
ToolDescription: description,
|
|
ToolSchema: schema,
|
|
ExecuteFunc: fn,
|
|
}
|
|
}
|