tool

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package tool exposes rag retrieval through the ordinary core Tool contract. A Retrieval accepts an already composed retriever and owns strict argument decoding and candidate result encoding without an Agent-specific API.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRetrieval

NewRetrieval adapts a rag.Retriever to the ordinary coretool.Tool contract. It can be advertised immediately or placed in an agent's DeferredTools set.

Example
package main

import (
	"context"
	jsonv2 "encoding/json/v2"
	"fmt"

	"github.com/Tangerg/scope/core/document"
	"github.com/Tangerg/scope/core/tool"
	"github.com/Tangerg/scope/rag"

	ragtool "github.com/Tangerg/scope/rag/tool"
)

func main() {
	retriever := rag.RetrieverFunc(func(_ context.Context, query rag.Query) (rag.Candidates, error) {
		doc, err := document.NewDocument(query.Text(), nil)
		if err != nil {
			return nil, err
		}
		return rag.Candidates{{Document: doc, Score: 1}}, nil
	})
	retrieval, err := ragtool.NewRetrieval(ragtool.RetrievalConfig{
		Name: "search", Description: "Retrieve evidence.", Retriever: retriever,
	})
	if err != nil {
		panic(err)
	}
	binding, err := tool.Bind(retrieval)
	if err != nil {
		panic(err)
	}
	invocation, err := binding.Contract().Prepare(tool.Request{Name: "search", Arguments: `{"query":"Go design"}`}, tool.Admission{})
	if err != nil {
		panic(err)
	}
	result, err := binding.Call(context.Background(), invocation)
	if err != nil {
		panic(err)
	}
	var output ragtool.RetrievalOutput
	if decodeErr := jsonv2.Unmarshal(result.Output.Details, &output); decodeErr != nil {
		panic(decodeErr)
	}
	fmt.Println(output.Candidates[0].Document.Text)
}
Output:
Go design

Types

type RetrievalConfig

type RetrievalConfig struct {
	Name        string
	Description string
	Retriever   rag.Retriever
}

RetrievalConfig describes a model-visible retrieval capability. Name and Description follow coretool.Definition requirements. Retriever is required and may already be composed with transformers, expansion, fusion, and refiners.

type RetrievalOutput

type RetrievalOutput struct {
	Candidates rag.Candidates `json:"candidates"`
}

type RetrievalRequest

type RetrievalRequest struct {
	Query string `json:"query" jsonschema:"minLength=1" jsonschema_description:"Natural-language query to retrieve evidence for."`
}

Jump to

Keyboard shortcuts

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