Documentation
¶
Index ¶
- func OptionalArg[T any](args map[string]any, name string) (T, bool)
- func RequiredArg[T any](args map[string]any, name string) T
- type Agent
- func (a *Agent) CurrentDeferredToolCalls() []DeferredToolCall
- func (a *Agent) Resume(ctx context.Context, callResults []DeferredCallResponse, ...) error
- func (a *Agent) Run(ctx context.Context, query string, messageCallback func(jpf.Message)) error
- func (a *Agent) Session() AgentSession
- func (a *Agent) SetMaxIterations(n int)
- func (a *Agent) SetSession(sess AgentSession)
- func (a *Agent) SetSkillCatalogue(skills []Skill)
- func (a *Agent) SetToolCatalogue(tools []Tool)
- type AgentSession
- type AgentSessionDTO
- type DeferredCallResponse
- type DeferredToolCall
- type DeferredToolCallDTO
- type Skill
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OptionalArg ¶
Fetches the arg from the tool args, must only be called on optional args defined int he schema.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
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 ¶
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 (*Agent) SetSession ¶
func (a *Agent) SetSession(sess AgentSession)
func (*Agent) SetSkillCatalogue ¶
func (*Agent) SetToolCatalogue ¶
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 DeferredToolCall ¶
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 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)
}