Plugin Smart Action
Overview
Smart Action is a plugin for ElizaOS that introduces a rapid development approach reminiscent of blockchain smart contracts. It leverages custom data structures and natural language state descriptions to automatically generate new state logic. When combined with an on-chain state storage plugin, it facilitates the swift creation of LLM-based smart contracts with efficient state management and flexible operations.
Features
- Rapid Plugin Development: Automatically generate state transformation logic using plain language descriptions and custom data structures.
- Natural Language Processing: Easily interpret state transitions described in English.
- On-Chain State Storage Integration: Securely persist and retrieve state data via on-chain storage plugins.
- Modular Design: Follows a blockchain smart contract style, making it easy to extend and maintain.
Technical Details
Data Structures & State Generation
- Custom Data Structures: Developers can define tailored state data structures that support both structured and unstructured data. These structures can be dynamically extended to accommodate evolving business requirements.
- Natural Language Descriptions: State transitions are described in plain English. The plugin automatically parses these descriptions to generate new state objects based on predefined JSON schemas.
- On-Chain Integration: The plugin seamlessly integrates with on-chain state storage, ensuring secure state persistence and consistent retrieval of historical state data.
Plugin Implementation
interface SmartActionService extends Service {
getInstance(): SmartActionService;
static get serviceType(): ServiceType;
async generateObject(
state: Record<string, any>,
prompt: string,
modelClass: ModelClass,
runtime: IAgentRuntime,
_message: Memory,
_state?: State,
): Promise<SmartActionResult>
}
This interface defines the core SmartActionService, which is responsible for generating new state objects based on the current state and a natural language prompt.
SmartActionResult Documentation
The result generated by the SmartActionService conforms to the SmartActionResult
interface. This interface encapsulates the outcome of the state transition process. Its structure is defined as follows:
interface SmartActionResult {
result: boolean | false; // Indicates whether the state transition was successful.
msg: string | null; // Provides a success confirmation or an error explanation.
states: [{
key: string; // The name of the state field that was updated.
value: string; // The new value for the state field.
}] | null; // An array of updated state entries.
}
All user state data that has been updated is stored in the states
array, making it straightforward for developers to retrieve and process the updated state information.