-
Notifications
You must be signed in to change notification settings - Fork 3
Components
theirish81 edited this page Jul 30, 2026
·
2 revisions
Plans can become quite messy. Prompts and data structures can occasionally repeat themselves, so it's useful to reduce
the noise by identifying and isolating reusable components.
At the plan level, components are defined in the components section.
Components can be:
-
Prompts: plain text, they are regular prompts or prePrompts -
Schemas: entire schemas or fragment of schemas that can be referenced and reused
Notes:
- Prompts have access to the invoker scope. This is pretty useful for parametrization
- If the main schema has declared
x-session, they will be used instead of the ones that may be defined in the$refschema. This is a variation of how JsonSchema and OpenAPI components work, but it's extremely useful in our case to enhance parametrization. - In the YAML example, note how "Prompts" is capitalized. This is because it's a predefined keyword in Frags. I know, it's painful to watch. Let's just accept it.
In the following example, we have two sessions, each one using the same prompts and schema, but with different behaviors, driven by the variables.
components:
prompts:
## Look at this prompt (that works as a prePrompt later. I generalized it by referencing a local var "company"
company_pre: |-
Search the internet for information about {{.vars.company}} including general information, pricing, and features
company_prompt: transform the data and fit it into the json structure
schemas:
## Here I came up with a common structure for all companies we're examining.
company:
type: object
required:
- general_information
- pricing
- features
properties:
general_information:
type: string
description: General information about the company
pricing:
type: string
description: Pricing options of the products
features:
type: array
description: Features of the products
items:
type: string
sessions:
acme:
prePrompt: "{{ .components.Prompts.company_pre }}"
prompt: "{{ .components.Prompts.company_prompt }}"
vars:
company: "Acme Inc."
tools:
- type: internet_search
foobar:
prePrompt: "{{ .components.Prompts.company_pre }}"
prompt: "{{ .components.Prompts.company_prompt }}"
vars:
company: "Foobar Inc."
tools:
- type: internet_search
schema:
type: object
properties:
acme:
x-session: acme
$ref: "#/components/schemas/company"
foobar:
x-session: foobar
$ref: "#/components/schemas/company"
sm.Components = frags.Components{
Prompts: map[string]string{
"company_pre": "Search the internet for information about {{.vars.company}} including general information, pricing, and features",
"company_prompt": "transform the data and fit it into the json structure",
},
Schemas: map[string]frags.Schema{
"company": {
Type: "object",
Properties: map[string]*frags.Schema{
"general_information": {
Type: "string",
Description: "General information about the company",
},
"pricing": {
Type: "string",
Description: "Pricing options of the products",
},
"features": {
Type: "string",
Description: "Features of the products",
},
},
},
},
}
sm.Sessions = frags.Sessions{
"acme": frags.Session{
PrePrompt: ptr("{{ .components.Prompts.company_pre }}"),
Prompt: "{{ .components.Prompts.company_prompt }}",
Vars: map[string]any{
"company": "Acme Inc",
},
Tools: frags.ToolDefinitions{
{
Type: frags.ToolTypeInternetSearch,
},
},
},
"foobar": frags.Session{
PrePrompt: ptr("{{ .components.Prompts.company_pre }}"),
Prompt: "{{ .components.Prompts.company_prompt }}",
Vars: map[string]any{
"company": "foobar Inc",
},
Tools: frags.ToolDefinitions{
{
Type: frags.ToolTypeInternetSearch,
},
},
},
}
sm.Schema = &frags.Schema{
Type: "object",
Properties: map[string]*frags.Schema{
"acme": {
XSession: ptr("acme"),
Ref: ptr("/components/schemas/company"),
},
"foobar": {
XSession: ptr("foobar"),
Ref: ptr("/components/schemas/company"),
},
},
}