agents

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptionalArg

func OptionalArg[T any](args map[string]any, name string) (T, bool)

Fetches the arg from the tool args, must only be called on optional args defined int he schema.

func RequiredArg

func RequiredArg[T any](args map[string]any, name string) T

Fetches the arg from the tool args, must only be called on required args defined int he schema.

Types

type Agent

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

func NewAgent

func NewAgent(model jpf.Model) *Agent

func (*Agent) CurrentDeferredToolCalls

func (a *Agent) CurrentDeferredToolCalls() []DeferredToolCall

func (*Agent) Resume

func (a *Agent) Resume(ctx context.Context, callResults []DeferredCallResponse, messageCallback func(jpf.Message)) error

Resume the agent from a set of responses to deferred tool calls to add into the conversation. Should only be called if the agent is currently awaiting deferred tool responses. May terminate because the agent is done, has hit max iterations, or is awaiting deferred tool responses.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, query string, messageCallback func(jpf.Message)) error

Run the agent from a new message to add into the conversation. Should only be called if the agent is not currently awaiting deferred tool responses. May terminate because the agent is done, has hit max iterations, or is awaiting deferred tool responses.

func (*Agent) Session

func (a *Agent) Session() AgentSession

func (*Agent) SetMaxIterations

func (a *Agent) SetMaxIterations(n int)

func (*Agent) SetSession

func (a *Agent) SetSession(sess AgentSession)

func (*Agent) SetSkillCatalogue

func (a *Agent) SetSkillCatalogue(skills []Skill)

func (*Agent) SetToolCatalogue

func (a *Agent) SetToolCatalogue(tools []Tool)

type AgentSession

type AgentSession struct {
	// The prompt that tells the agent how to interact with the agent loop and react loop,
	// usually does not need to be changed.
	AgentPrompt string
	// The prompt telling the agent specifically about its task,
	// if not specified will tell the agent to be a generalist.
	TaskPrompt string
	// The prompt telling the agent how to act / speak,
	// if not specified will speak neutrally and refer to itself as AI Assistant.
	PersonalityPrompt string
	// The messages, excluding system and other special messages.
	CoreMessages []jpf.Message
	// The current tool calls that have been deferred, with their validated args.
	CurrentDeferredToolCalls []DeferredToolCall
	// The names of the skills that should currently be active.
	ActiveSkillNames []string
}

An agent session describes the state of an agent at the current point in time, avoiding any specific logic or details of skills.

func DefaultSession

func DefaultSession() AgentSession

func (AgentSession) Clone

func (a AgentSession) Clone() AgentSession

type AgentSessionDTO

type AgentSessionDTO struct {
	AgentPrompt              string                `json:"agent_prompt"`
	TaskPrompt               string                `json:"task_prompt"`
	PersonalityPrompt        string                `json:"personality_prompt"`
	CoreMessages             []jpf.MessageDTO      `json:"core_messages,omitempty"`
	CurrentDeferredToolCalls []DeferredToolCallDTO `json:"current_deferred_tool_calls,omitempty"`
	ActiveSkillNames         []string              `json:"active_skill_names,omitempty"`
}

AgentSessionDTO is a JSON-serialisable representation of an AgentSession.

Populate it from a session with LoadSession, and convert it back with ToSession.

Round-tripping is not exactly lossless:

  • Every message in CoreMessages carries the jpf.MessageDTO caveats (tool-arg numbers come back as float64, image attachments are re-encoded as PNG and will not compare Eq).
  • The arguments of a deferred tool call also pass through JSON as float64. These args have already been validated and coerced against their tool schema (e.g. ints stored as int), and that coercion is undone by the round-trip. However, it is expected the user of the framework will have triggered the background job already for that call, so this should not matter.

func (*AgentSessionDTO) LoadSession

func (d *AgentSessionDTO) LoadSession(sess AgentSession) error

LoadSession populates the DTO in place from sess, replacing any existing contents.

func (*AgentSessionDTO) ToSession

func (d *AgentSessionDTO) ToSession() (AgentSession, error)

ToSession converts the DTO back into the AgentSession it represents.

type DeferredCallResponse

type DeferredCallResponse struct {
	CallID string
	Result string
	Err    error
}

type DeferredToolCall

type DeferredToolCall struct {
	ToolName string
	CallID   string
	Args     map[string]any
}

type DeferredToolCallDTO

type DeferredToolCallDTO struct {
	ToolName string         `json:"tool_name"`
	CallID   string         `json:"call_id"`
	Args     map[string]any `json:"args,omitempty"`
}

DeferredToolCallDTO is a JSON-serialisable representation of a DeferredToolCall.

func (*DeferredToolCallDTO) LoadDeferredToolCall

func (d *DeferredToolCallDTO) LoadDeferredToolCall(call DeferredToolCall)

LoadDeferredToolCall populates the DTO in place from call, replacing any existing contents.

func (*DeferredToolCallDTO) ToDeferredToolCall

func (d *DeferredToolCallDTO) ToDeferredToolCall() DeferredToolCall

ToDeferredToolCall converts the DTO back into the DeferredToolCall it represents.

type Skill

type Skill struct {
	Name        string
	Description string
	Content     string
}

type Tool

type Tool struct {
	// How and when can the agent call the tool, and what it should expect it to do.
	Schema jpf.ToolSchema
	// How should the agent framework run the tool.
	// If not specified, the agent framework will break the loop and defer.
	Call func(context.Context, map[string]any) (string, error)
}

Jump to

Keyboard shortcuts

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