Skip to content

Resources

theirish81 edited this page Aug 27, 2026 · 4 revisions

Resources

While you can certainly use MCP servers and functions to access resources, Frags provides a more convenient way to load resources that are already available for the plan to use, and that is resources.

Resources can be text files (plain text, csv, json...) or binary files (pdf).

Resource routing

Ai

As a default, a resource is simply loaded into the LLM context (in: ai). In this way the LLM will be capable of using the resource and answer questions about it.

Vars

By declaring its route as in: vars text files can be used by the plan as a variable. This allows to use a resource to control the behavior of plan. When routed to vars, its content will be available to expressions, such as: iterateOn: vars.my_resource or to templates, as in: {{ .vars.my_resource }}.

Important: if routed to vars, the attribute var with the variable name is required.

Transformers

Resources can be transformed using transformers. Depending on the routing, this could lead to a modified resource to be available in the LLM context, or even make a resource in session vars into a structured object.

Resource loaders

A resource loader is assigned to a Runner, and the plan is almost entirely oblivious of how the files are loaded. From the plan point of view, all resource loaders have the same interface.

FileResourceLoader

It's the default resource loader in the CLI, and allows you to access the local file system.

BEWARE Security concern: do not use this resource loader in internet accessible or shared applications! This resource loader will load any file described in a plan.

BytesResourceLoader

This resource loader, to be used mostly in integrations scenarios, allows the plan to load a file that has already been loaded into memory by the integration layer.

MultiResourceLoader

Is an aggregation loader in which a plan can define which sub-loader to use using the loader parameter.

CLI

The CLI uses the FileResourceLoader by default. To load a resource into the LLM context, use the resources block, as in:

sessions:
  basic_extraction:
    prompt: extract the patient details details from the attached discharge note
    resources:
      - identifier: discharge.pdf

If we want to route a text file to the session vars, you can:

sessions:
  basic_extraction:
    prompt: What is the patient name in {{ .vars.patient }}
    resources:
      - identifier: data.txt
        in: vars
        var: patient

Go

To instantiate a runner with a given resource loader:

runner := frags.NewRunner[frags.ProgMap](sm, frags.NewFileResourceLoader(dir), ai)

and in the session, reference the resource loader by:

session.Resources = []frags.Resource{
    {
        Identifier: "patient.pdf",
    },
}

To implement your own resource loader, implement the frags.ResourceLoader interface.

Caveats and limitations

The nature of the usable resources depends on the LLM implementation.

  • Gemini supports most type of document files
  • ChatGPT supports PDF and most text files
  • Ollama currently supports only text files

Clone this wiki locally