Documentation
¶
Index ¶
- func AppendInstructions(r *model.LLMRequest, instructions ...string)
- func CanonicalSchemaJSON(s *jsonschema.Schema) ([]byte, error)
- func Content(ev *session.Event) *genai.Content
- func EventBelongsToBranch(invocationBranch, eventBranch string) bool
- func FunctionCalls(c *genai.Content) (ret []*genai.FunctionCall)
- func FunctionDecls(c *genai.GenerateContentConfig) (ret []*genai.FunctionDeclaration)
- func FunctionResponses(c *genai.Content) (ret []*genai.FunctionResponse)
- func GenerateFunctionCallID(ctx context.Context) string
- func IsProsePart(p *genai.Part) bool
- func Must[T agent.Agent](a T, err error) T
- func PopulateClientFunctionCallID(ctx context.Context, c *genai.Content)
- func RemoveClientFunctionCallID(c *genai.Content)
- func TextParts(c *genai.Content) (ret []string)
- func ValidateMapOnSchema(args map[string]any, schema *genai.Schema, isInput bool) error
- func ValidateOutputSchema(output string, schema *genai.Schema) (map[string]any, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendInstructions ¶
func AppendInstructions(r *model.LLMRequest, instructions ...string)
AppendInstructions appends instructions to the genai.GenerateContentConfig.SystemInstruction system instruction.
func CanonicalSchemaJSON ¶
func CanonicalSchemaJSON(s *jsonschema.Schema) ([]byte, error)
CanonicalSchemaJSON marshals the schema to JSON, parses it back, and re-emits it with object keys sorted alphabetically (recursively). Arrays keep their original order, except the unordered set keywords (see unorderedArrayKeywords), whose elements are sorted so that equivalent schemas canonicalize identically.
func EventBelongsToBranch ¶ added in v2.3.0
EventBelongsToBranch reports whether an event on eventBranch is visible to an invocation running on invocationBranch.
An event belongs to its own branch and to every descendant of it, so a child agent sees what its parent said and not the other way round. Branch nodes are delimited with a dot, and the prefix match requires that dot so that "agent_0" does not match "agent_00".
The single definition, because prompt assembly and anything reasoning about what a prompt contains have to agree on it.
func FunctionCalls ¶
func FunctionCalls(c *genai.Content) (ret []*genai.FunctionCall)
Belows are useful utilities that help working with genai.Content included in types.Event. TODO: Use generics. FunctionCalls extracts all FunctionCall parts from the content.
func FunctionDecls ¶
func FunctionDecls(c *genai.GenerateContentConfig) (ret []*genai.FunctionDeclaration)
FunctionDecls extracts all Function declarations from the GenerateContentConfig.
func FunctionResponses ¶
func FunctionResponses(c *genai.Content) (ret []*genai.FunctionResponse)
FunctionResponses extracts all FunctionResponse parts from the content.
func GenerateFunctionCallID ¶
GenerateFunctionCallID generates a new function call ID. The ID is obtained through the platform package, so a UUID provider installed on ctx (see platform.WithUUIDProvider) controls it.
func IsProsePart ¶ added in v2.3.0
IsProsePart reports whether p is plain text meant to be read, and nothing else.
Exactly one field of a genai.Part is meant to be set, so a part carrying any of the actionable payloads is not prose whatever else is on it. Callers that filter on this drop such a part rather than reducing it to its text: the text is not what makes it dangerous, and dropping is the conservative half of the choice.
A thought is not prose either. It is the model's private reasoning rather than anything it chose to say, and it should not be stored or replayed as though the model had said it.
func PopulateClientFunctionCallID ¶
PopulateClientFunctionCallID sets the function call ID field if it is empty. Since the ID field is optional, some models don't fill the field, but the LLMAgent depends on the IDs to map FunctionCall and FunctionResponse events in the event stream.
func RemoveClientFunctionCallID ¶
RemoveClientFunctionCallID removes the function call ID field that was set by populateClientFunctionCallID. This is necessary when FunctionCall or FunctionResponse are sent back to the model.
func ValidateMapOnSchema ¶
ValidateMapOnSchema validates a map against a schema.
Types ¶
This section is empty.