agent

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ACPAgent

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

ACPAgent communicates with ACP-compatible agents (claude-agent-acp, codex-acp, cursor agent, etc.) via stdio JSON-RPC 2.0.

func NewACPAgent

func NewACPAgent(cfg ACPAgentConfig) *ACPAgent

NewACPAgent creates a new ACP agent.

func (*ACPAgent) Chat

func (a *ACPAgent) Chat(ctx context.Context, conversationID string, message string) (string, error)

Chat sends a message and returns the full response.

func (*ACPAgent) ChatWithImage added in v0.8.0

func (a *ACPAgent) ChatWithImage(ctx context.Context, conversationID string, message string, image *ImageInput) (string, error)

ChatWithImage sends a message with an image to the agent.

func (*ACPAgent) Info

func (a *ACPAgent) Info() AgentInfo

Info returns metadata about this agent.

func (*ACPAgent) ResetSession added in v0.5.0

func (a *ACPAgent) ResetSession(ctx context.Context, conversationID string) (string, error)

ResetSession clears the existing session for the given conversationID and immediately creates a new one, returning the new session ID.

func (*ACPAgent) SetCwd added in v0.5.0

func (a *ACPAgent) SetCwd(cwd string)

SetCwd changes the working directory for subsequent sessions.

func (*ACPAgent) Start

func (a *ACPAgent) Start(ctx context.Context) error

Start launches the claude-agent-acp subprocess and initializes the connection.

func (*ACPAgent) Stop

func (a *ACPAgent) Stop()

Stop terminates the subprocess.

type ACPAgentConfig

type ACPAgentConfig struct {
	Command      string   // path to ACP agent binary (claude-agent-acp, codex-acp, cursor agent, etc.)
	Args         []string // extra args for command (e.g. ["acp"] for cursor)
	Model        string
	SystemPrompt string
	Cwd          string            // working directory
	Env          map[string]string // extra environment variables
}

ACPAgentConfig holds configuration for the ACP agent.

type Agent

type Agent interface {
	// Chat sends a message to the agent and returns the response.
	// conversationID is used to maintain conversation history per user.
	Chat(ctx context.Context, conversationID string, message string) (string, error)

	// ResetSession clears the existing session for the given conversationID and
	// starts a new one. Returns the new session ID if immediately available
	// (ACP mode), or an empty string if the ID will be assigned on next Chat
	// (CLI mode) or is not applicable (HTTP mode).
	ResetSession(ctx context.Context, conversationID string) (string, error)

	// Info returns metadata about this agent.
	Info() AgentInfo

	// SetCwd changes the working directory for subsequent operations.
	SetCwd(cwd string)
}

Agent is the interface for AI chat agents.

type AgentInfo

type AgentInfo struct {
	Name    string // e.g. "claude-acp", "claude", "gpt-4o"
	Type    string // e.g. "acp", "cli", "http"
	Model   string // e.g. "sonnet", "gpt-4o-mini"
	Command string // binary path, e.g. "/usr/local/bin/claude-agent-acp"
	PID     int    // subprocess PID (0 if not applicable, e.g. http agent)
}

AgentInfo holds metadata about an agent for logging/debugging.

func (AgentInfo) String

func (i AgentInfo) String() string

String returns a human-readable summary for logging.

type CLIAgent

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

CLIAgent invokes a local CLI agent (claude, codex, etc.) via streaming JSON.

func NewCLIAgent

func NewCLIAgent(cfg CLIAgentConfig) *CLIAgent

NewCLIAgent creates a new CLI agent.

func (*CLIAgent) Chat

func (a *CLIAgent) Chat(ctx context.Context, conversationID string, message string) (string, error)

Chat sends a message to the CLI agent and returns the response.

func (*CLIAgent) Info

func (a *CLIAgent) Info() AgentInfo

Info returns metadata about this agent.

func (*CLIAgent) ResetSession added in v0.5.0

func (a *CLIAgent) ResetSession(_ context.Context, conversationID string) (string, error)

ResetSession clears the existing session for the given conversationID. Returns an empty string because the new session ID is only known after the next Chat call (claude assigns it during the conversation).

func (*CLIAgent) SetCwd added in v0.5.0

func (a *CLIAgent) SetCwd(cwd string)

SetCwd changes the working directory for subsequent CLI invocations.

type CLIAgentConfig

type CLIAgentConfig struct {
	Name         string            // agent name for logging, e.g. "claude", "codex"
	Command      string            // path to binary
	Args         []string          // extra args (e.g. ["--dangerously-skip-permissions"])
	Cwd          string            // working directory (workspace)
	Env          map[string]string // extra environment variables
	Model        string
	SystemPrompt string
}

CLIAgentConfig holds configuration for a CLI agent.

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

ChatMessage represents a single message in a conversation.

type HTTPAgent

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

HTTPAgent is an OpenAI-compatible chat completions API client.

func NewHTTPAgent

func NewHTTPAgent(cfg HTTPAgentConfig) *HTTPAgent

NewHTTPAgent creates a new OpenAI-compatible HTTP agent.

func (*HTTPAgent) Chat

func (a *HTTPAgent) Chat(ctx context.Context, conversationID string, message string) (string, error)

Chat sends a message to the OpenAI-compatible API and returns the response.

func (*HTTPAgent) Info

func (a *HTTPAgent) Info() AgentInfo

Info returns metadata about this agent.

func (*HTTPAgent) ResetSession added in v0.5.0

func (a *HTTPAgent) ResetSession(_ context.Context, conversationID string) (string, error)

ResetSession clears the conversation history for the given conversationID. HTTP agents have no server-side session ID, so an empty string is returned.

func (*HTTPAgent) SetCwd added in v0.5.0

func (a *HTTPAgent) SetCwd(_ string)

SetCwd is a no-op for HTTP agents (they have no working directory).

type HTTPAgentConfig

type HTTPAgentConfig struct {
	Endpoint     string
	APIKey       string
	Model        string
	SystemPrompt string
	MaxHistory   int
}

HTTPAgentConfig holds configuration for the HTTP agent.

type ImageChatAgent added in v0.8.0

type ImageChatAgent interface {
	Agent
	ChatWithImage(ctx context.Context, conversationID string, message string, image *ImageInput) (string, error)
}

ImageChatAgent is an optional interface for agents that support image input.

type ImageInput added in v0.8.0

type ImageInput struct {
	MimeType string // e.g. "image/jpeg", "image/png"
	Data     []byte // raw image bytes
}

ImageInput holds image data for multimodal chat.

type ShellAgent added in v0.8.0

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

ShellAgent executes shell commands directly and returns their output. It allows users to run arbitrary commands from WeChat and see the results.

func NewShellAgent added in v0.8.0

func NewShellAgent(cfg ShellAgentConfig) *ShellAgent

NewShellAgent creates a new shell agent.

func (*ShellAgent) Chat added in v0.8.0

func (a *ShellAgent) Chat(ctx context.Context, _ string, message string) (string, error)

Chat executes the message as a shell command and returns stdout+stderr.

func (*ShellAgent) Info added in v0.8.0

func (a *ShellAgent) Info() AgentInfo

Info returns metadata about this agent.

func (*ShellAgent) ResetSession added in v0.8.0

func (a *ShellAgent) ResetSession(_ context.Context, _ string) (string, error)

ResetSession is a no-op for shell agents (no session state).

func (*ShellAgent) SetCwd added in v0.8.0

func (a *ShellAgent) SetCwd(cwd string)

SetCwd changes the working directory for subsequent commands.

type ShellAgentConfig added in v0.8.0

type ShellAgentConfig struct {
	Name    string
	Shell   string            // shell binary (defaults to /bin/sh)
	Cwd     string            // working directory
	Env     map[string]string // extra environment variables
	Aliases []string
}

ShellAgentConfig holds configuration for a shell agent.

Jump to

Keyboard shortcuts

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