tool

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 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

This section is empty.

Types

type Retrieval

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

Retrieval 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"
	"encoding/json"
	"fmt"

	"github.com/Tangerg/scope/core/chat"
	"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(chat.ToolCall{
		ID: "search-1", Name: "search", Arguments: `{"query":"Go design"}`,
	})
	if err != nil {
		panic(err)
	}
	result, err := binding.Call(context.Background(), invocation)
	if err != nil {
		panic(err)
	}
	var output ragtool.RetrievalOutput
	if decodeErr := json.Unmarshal(result.Details, &output); decodeErr != nil {
		panic(decodeErr)
	}
	fmt.Println(output.Candidates[0].Document.Text)
}
Output:
Go design

func NewRetrieval

func NewRetrieval(config RetrievalConfig) (Retrieval, error)

NewRetrieval exposes a composed Retriever through the ordinary core tool contract without adding Agent-specific retrieval semantics.

func (Retrieval) Call

func (r Retrieval) Call(ctx context.Context, invocation coretool.Invocation) (chat.ToolOutput, error)

func (Retrieval) Definition

func (r Retrieval) Definition() chat.ToolDefinition

func (Retrieval) Unwrap added in v0.19.0

func (r Retrieval) Unwrap() coretool.Tool

Unwrap exposes the typed input contract through tool decorators.

type RetrievalConfig

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

RetrievalConfig describes a model-visible retrieval capability. Name and Description follow chat.ToolDefinition 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"`
}

RetrievalOutput is the model-visible retrieval result.

type RetrievalRequest

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

RetrievalRequest is the strict model-generated tool input.

Jump to

Keyboard shortcuts

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