Expand description
Abstract Syntax Tree types for AgentScript.
This module defines all types representing a parsed AgentScript file.
Every node in the AST is wrapped in Spanned to track its source location,
enabling precise error reporting and IDE features like go-to-definition.
For a comprehensive guide to the AST structure, node relationships, and UX development patterns, see the AST Reference.
§AST Structure
The root type is AgentFile, which contains optional blocks:
AgentFile
├── config: ConfigBlock (agent metadata)
├── system: SystemBlock (global instructions/messages)
├── variables: VariablesBlock (state management)
├── connections: ConnectionsBlock (escalation routing)
├── language: LanguageBlock (locale settings)
├── start_agent: StartAgentBlock (entry point)
└── topics: Vec<TopicBlock> (conversation topics)§Span Tracking
All nodes use Spanned<T> to preserve source locations:
use busbar_sf_agentscript::Spanned;
// A spanned string with byte offsets 10..20
let name = Spanned::new("MyAgent".to_string(), 10..20);
assert_eq!(name.node, "MyAgent");
assert_eq!(name.span, 10..20);§Serialization
All types implement Serialize and Deserialize for JSON interop:
let source = "config:\n agent_name: \"Test\"\n";
let agent = parse(source).unwrap();
let json = serde_json::to_string(&agent).unwrap();Structs§
- Action
Def - An action definition.
- Actions
Block - A block of action definitions.
- Agent
File - A complete parsed AgentScript file.
- Comment
- A comment in the source.
- Config
Block - Agent configuration block containing metadata.
- Connection
Block - A connection block defines escalation routing for a specific channel.
- Connection
Entry - A key-value entry in a connection block.
- Directive
Block - A directive block contains imperative statements.
- IfClause
- A conditional clause in reasoning actions.
- Knowledge
Block - The knowledge block configures knowledge base access.
- Knowledge
Entry - Language
Block - The language block configures locale settings.
- Language
Entry - Output
Ref - Reference to an action output.
- Param
Def - A parameter definition (for action inputs/outputs).
- Reasoning
Action - An action available during reasoning.
- Reasoning
Block - The reasoning block configures LLM reasoning.
- Reference
- A reference to a namespaced resource.
- RunClause
- A chained run clause in reasoning actions.
- SetClause
- A set clause assigns a value to a variable.
- Spanned
- A value with an associated source span.
- Start
Agent Block - The start_agent block is the entry point for the agent.
- System
Block - The system block defines global agent settings.
- System
Messages - System messages (welcome, error).
- Topic
Block - A topic block defines a conversation topic.
- Topic
System Override - System instruction override for a topic.
- Variable
Decl - A single variable declaration.
- Variables
Block - Variables block containing state variable declarations.
- With
Clause - A with clause binds an action input.
Enums§
- BinOp
- Binary operators.
- Expr
- An expression in AgentScript.
- Instruction
Part - A part of dynamic instructions.
- Instructions
- Instructions can be static or dynamic.
- Reasoning
Action Target - Target of a reasoning action.
- Stmt
- A statement in a directive block.
- Type
- Data type for variables and action parameters.
- UnaryOp
- Unary operators.
- Variable
Kind - Variable mutability kind.
- With
Value - The value of a with clause.
Type Aliases§
- Connections
Block - @deprecated Use ConnectionBlock instead - this type exists only for backwards compatibility
- Span
- A span in the source code represented as byte offsets.