Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CsvFormatAgent ¶
type CsvFormatAgent struct {
// contains filtered or unexported fields
}
CsvFormatAgent formats a CSV file into a RAG-optimised plain-text representation. Each row (or logical group of rows) is rewritten as an independent, self-contained paragraph suitable for semantic chunking and vector retrieval.
Use NewCsvFormatAgent to create an instance, then call CsvFormatAgent.Format to process a file.
func NewCsvFormatAgent ¶
func NewCsvFormatAgent(chatModel model.ToolCallingChatModel, opts ...CsvFormatOption) (*CsvFormatAgent, error)
NewCsvFormatAgent compiles and returns a new CsvFormatAgent.
Example:
agent, err := prebuilt.NewCsvFormatAgent(chatModel,
prebuilt.WithCsvFormatMaxRunSteps(30),
prebuilt.WithCsvFormatLanguage("Chinese"),
)
func (*CsvFormatAgent) Format ¶
Format reads the CSV file at srcPath, runs the formatting agent, and writes the resulting plain-text output to dstPath.
The agent reads /input/data.csv from the virtual backend, transforms the content into RAG-optimised paragraphs, and writes the result to /output/context.txt. The output file is registered as an artifact and then written to dstPath.
Returns an error if the file cannot be read, the agent fails, or no artifact is produced.
type CsvFormatOption ¶
type CsvFormatOption func(o *csvFormatConfig)
CsvFormatOption configures a CsvFormatAgent.
func WithCsvFormatLanguage ¶
func WithCsvFormatLanguage(lang string) CsvFormatOption
WithCsvFormatLanguage sets the language for agent responses and selects the matching task prompt. Supported values: "Chinese" (default), any other value selects the English prompt.
func WithCsvFormatMaxRunSteps ¶
func WithCsvFormatMaxRunSteps(n int) CsvFormatOption
WithCsvFormatMaxRunSteps sets the maximum number of graph steps before the agent terminates. If 0, no limit is applied.
type FactCheckAgent ¶
type FactCheckAgent struct {
// contains filtered or unexported fields
}
FactCheckAgent evaluates the factual accuracy of an LLM response against a knowledge context, a user question, and an optional reference answer.
The agent performs a single-shot call using agentloop.Agent with no tools.
Use NewFactCheckAgent to create an instance, then call FactCheckAgent.Check to score a response.
func NewFactCheckAgent ¶
func NewFactCheckAgent(chatModel model.ToolCallingChatModel, opts ...FactCheckOption) (*FactCheckAgent, error)
NewFactCheckAgent creates a new FactCheckAgent backed by the given chat model.
Example:
agent, err := prebuilt.NewFactCheckAgent(chatModel)
result, err := agent.Check(rail, prebuilt.FactCheckInput{
Question: "What is the capital of France?",
Context: "France is a country in Western Europe. Its capital is Paris.",
Output: "The capital of France is Paris.",
ReferenceAnswer: "Paris",
})
func (*FactCheckAgent) Check ¶
func (a *FactCheckAgent) Check(rail flow.Rail, input FactCheckInput) (FactCheckResult, error)
Check evaluates the factual accuracy of an LLM response and returns a FactCheckResult.
The prompt template is substituted with the provided inputs using strutil.NamedSprintfv. The model response is parsed for "Score:" and "Reason:" fields. If either field is missing the call is retried up to [factCheckConfig.RetryCount] additional times.
func (*FactCheckAgent) CheckCtx ¶
func (a *FactCheckAgent) CheckCtx(ctx context.Context, input FactCheckInput) (FactCheckResult, error)
CheckCtx is like FactCheckAgent.Check but accepts a plain context.Context.
type FactCheckInput ¶
type FactCheckInput struct {
// Question is the user question that prompted the LLM response.
Question string
// Context is the knowledge context retrieved for the question.
Context string
// Output is the LLM response to be evaluated.
Output string
// ReferenceAnswer is the ground-truth answer used for comparison.
// May be left empty if no reference is available; the agent will rely on Context alone.
ReferenceAnswer string
}
FactCheckInput holds all the inputs required for a single fact-checking call.
type FactCheckOption ¶
type FactCheckOption func(o *factCheckConfig)
FactCheckOption configures a FactCheckAgent.
func WithFactCheckLanguage ¶
func WithFactCheckLanguage(lang string) FactCheckOption
WithFactCheckLanguage sets the response language for the fact-check agent.
func WithFactCheckRetry ¶
func WithFactCheckRetry(n int) FactCheckOption
WithFactCheckRetry sets the number of additional retry attempts when the model response is missing a Score or Reason field. The default is 2 (up to 3 total attempts).
func WithFactCheckSystemPrompt ¶
func WithFactCheckSystemPrompt(prompt string) FactCheckOption
WithFactCheckSystemPrompt sets an optional system prompt for the fact-check agent.
type FactCheckResult ¶
type FactCheckResult struct {
// Score is the factual accuracy score on a 1-5 scale:
// 1 = Major factual errors or hallucinations
// 2 = Significant inaccuracies affecting core meaning
// 3 = Partially correct but with key mistakes
// 4 = Minor inaccuracies in non-critical details
// 5 = Fully factually correct with no errors
Score int
// Reason is a brief textual justification for the score.
Reason string
}
FactCheckResult holds the numeric score and textual reason returned by the agent.
type RelevanceCheckAgent ¶
type RelevanceCheckAgent struct {
// contains filtered or unexported fields
}
RelevanceCheckAgent evaluates how relevant an LLM response is to the user question, knowledge context, and optional reference answer.
The agent performs a single-shot call using agentloop.Agent with no tools.
Use NewRelevanceCheckAgent to create an instance, then call RelevanceCheckAgent.Check to score a response.
func NewRelevanceCheckAgent ¶
func NewRelevanceCheckAgent(chatModel model.ToolCallingChatModel, opts ...RelevanceCheckOption) (*RelevanceCheckAgent, error)
NewRelevanceCheckAgent creates a new RelevanceCheckAgent backed by the given chat model.
Example:
agent, err := prebuilt.NewRelevanceCheckAgent(chatModel)
result, err := agent.Check(rail, prebuilt.RelevanceCheckInput{
Question: "What is the capital of France?",
Context: "France is a country in Western Europe. Its capital is Paris.",
Output: "The capital of France is Paris.",
})
func (*RelevanceCheckAgent) Check ¶
func (a *RelevanceCheckAgent) Check(rail flow.Rail, input RelevanceCheckInput) (RelevanceCheckResult, error)
Check evaluates the relevance of an LLM response and returns a RelevanceCheckResult.
The prompt template is substituted with the provided inputs using strutil.NamedSprintfv. The model response is parsed for "Score:" and "Reason:" fields. If either field is missing the call is retried up to [relevanceCheckConfig.RetryCount] additional times.
func (*RelevanceCheckAgent) CheckCtx ¶
func (a *RelevanceCheckAgent) CheckCtx(ctx context.Context, input RelevanceCheckInput) (RelevanceCheckResult, error)
CheckCtx is like RelevanceCheckAgent.Check but accepts a plain context.Context.
type RelevanceCheckInput ¶
type RelevanceCheckInput struct {
// Question is the user question that prompted the LLM response.
Question string
// Context is the knowledge context retrieved for the question.
Context string
// Output is the LLM response to be evaluated.
Output string
// ReferenceAnswer is the ground-truth answer used for comparison.
// May be left empty if no reference is available; the agent will rely on Context alone.
ReferenceAnswer string
}
RelevanceCheckInput holds all the inputs required for a single relevance-check call.
type RelevanceCheckOption ¶
type RelevanceCheckOption func(o *relevanceCheckConfig)
RelevanceCheckOption configures a RelevanceCheckAgent.
func WithRelevanceCheckLanguage ¶
func WithRelevanceCheckLanguage(lang string) RelevanceCheckOption
WithRelevanceCheckLanguage sets the response language for the relevance-check agent.
func WithRelevanceCheckRetry ¶
func WithRelevanceCheckRetry(n int) RelevanceCheckOption
WithRelevanceCheckRetry sets the number of additional retry attempts when the model response is missing a Score or Reason field. The default is 2 (up to 3 total attempts).
func WithRelevanceCheckSystemPrompt ¶
func WithRelevanceCheckSystemPrompt(prompt string) RelevanceCheckOption
WithRelevanceCheckSystemPrompt sets an optional system prompt for the relevance-check agent.
type RelevanceCheckResult ¶
type RelevanceCheckResult struct {
// Score is the relevance score on a 1-5 scale:
// 1 = Completely irrelevant
// 2 = Mostly irrelevant
// 3 = Somewhat relevant but with noticeable issues
// 4 = Mostly relevant with minor issues
// 5 = Fully correct and accurate
Score int
// Reason is a brief textual justification for the score.
Reason string
}
RelevanceCheckResult holds the numeric relevance score and textual reason returned by the agent.