Actions
Building blocks of SpinAI agents
What are Actions?
Actions are discrete tasks that your AI agent can perform. They are:
- Type-safe and predictable
- Parameter-driven with state awareness
- Dependency-aware
- Reusable across agents
Creating Actions
Use the createAction
function to define actions:
Action Configuration
Parameters and State
Actions can receive input through parameters and access shared state through context:
Example using parameters and context:
Parameter Resolution
SpinAI’s task loop follows a two-step decision process:
-
Action Selection
- First, the LLM decides which action(s) to run based on the current context and goal
- This decision is made using the action’s description, the current state, and the user’s input
-
Parameter Determination
- Before executing the chosen action, SpinAI makes a separate decision to determine the exact parameters
- Parameters are intelligently derived from:
- Results of previously run actions
- Current application state
- User’s original input
- Any other available context
For example, in a calculator agent:
Dependencies
Actions can depend on other actions:
SpinAI automatically:
- Resolves dependency order
- Ensures prerequisites run first
- Prevents circular dependencies
- Handles parallel execution when possible
Best Practices
-
Clear Parameter Schemas Define clear parameter types and descriptions:
-
Descriptive Action Descriptions Help the LLM understand both when to use the action AND what parameters it needs:
-
State Management While parameters are preferred for inputs, use state for:
- Storing action results
- Sharing data between actions
- Maintaining conversation context
-
Error Handling Validate parameters and use the retry system for unreliable operations: