|
| 1 | +# Sim Studio SDK |
| 2 | + |
| 3 | +The Sim Studio SDK allows developers to create, manage, and deploy workflows programmatically. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @sim-studio/sdk |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +### Creating a Simple Workflow |
| 14 | + |
| 15 | +```typescript |
| 16 | +import { SimStudio, AgentBlock, FunctionBlock } from '@sim-studio/sdk'; |
| 17 | + |
| 18 | +// Initialize the SDK |
| 19 | +const simStudio = new SimStudio({ |
| 20 | + apiKey: 'your-api-key', |
| 21 | +}); |
| 22 | + |
| 23 | +// Create a workflow |
| 24 | +const workflow = simStudio.createWorkflow( |
| 25 | + 'Simple Workflow', |
| 26 | + 'A simple workflow that uses an agent to generate content' |
| 27 | +); |
| 28 | + |
| 29 | +// Create an agent block |
| 30 | +const agentBlock = new AgentBlock({ |
| 31 | + model: 'claude-3-7-sonnet', |
| 32 | + prompt: 'Write a blog post about <input.topic>', |
| 33 | + systemPrompt: 'You are a professional content writer.', |
| 34 | +}); |
| 35 | + |
| 36 | +// Create a function block to format the content |
| 37 | +const formatterBlock = new FunctionBlock({ |
| 38 | + code: ` |
| 39 | + function formatContent(input) { |
| 40 | + return { |
| 41 | + title: "Blog: " + input.topic, |
| 42 | + content: input.content, |
| 43 | + wordCount: input.content.split(' ').length |
| 44 | + }; |
| 45 | + } |
| 46 | + ` |
| 47 | +}); |
| 48 | + |
| 49 | +// Add blocks to the workflow |
| 50 | +workflow.addBlock(agentBlock); |
| 51 | +workflow.addBlock(formatterBlock); |
| 52 | + |
| 53 | +// Connect blocks |
| 54 | +const starterBlock = workflow.getStarterBlock(); |
| 55 | +workflow.connect(starterBlock.id, agentBlock.id); |
| 56 | +workflow.connect(agentBlock.id, formatterBlock.id); |
| 57 | + |
| 58 | +// Build and save the workflow |
| 59 | +const builtWorkflow = workflow.build(); |
| 60 | +simStudio.saveWorkflow(builtWorkflow) |
| 61 | + .then(savedWorkflow => { |
| 62 | + console.log(`Workflow saved with ID: ${savedWorkflow.id}`); |
| 63 | + }); |
| 64 | +``` |
| 65 | + |
| 66 | +### Using Tools with Agents |
| 67 | + |
| 68 | +Agent blocks can use tools for enhanced capabilities. You can simply reference built-in tools by ID or define custom tools: |
| 69 | + |
| 70 | +```typescript |
| 71 | +import { SimStudio, AgentBlock } from '@sim-studio/sdk'; |
| 72 | + |
| 73 | +// Initialize the SDK |
| 74 | +const simStudio = new SimStudio({ |
| 75 | + apiKey: 'your-api-key', |
| 76 | +}); |
| 77 | + |
| 78 | +// Create a workflow |
| 79 | +const workflow = simStudio.createWorkflow('Research Assistant'); |
| 80 | + |
| 81 | +// Create an agent block |
| 82 | +const researchAgent = new AgentBlock({ |
| 83 | + model: 'claude-3-opus', |
| 84 | + prompt: 'Research the topic "{{input.topic}}" and provide a comprehensive summary.', |
| 85 | + systemPrompt: 'You are a research assistant.', |
| 86 | + tools: [] // Will be populated with tool references |
| 87 | +}); |
| 88 | + |
| 89 | +// Reference built-in tools by their IDs |
| 90 | +// The system will automatically transform these references into tool definitions |
| 91 | +researchAgent.data.toolReferences = ['tavily_search', 'serper_search']; |
| 92 | + |
| 93 | +// Configure tool settings with required parameters |
| 94 | +researchAgent.data.toolSettings = { |
| 95 | + tavily_search: { |
| 96 | + apiKey: 'your-tavily-api-key' |
| 97 | + }, |
| 98 | + serper_search: { |
| 99 | + apiKey: 'your-serper-api-key' |
| 100 | + } |
| 101 | +}; |
| 102 | + |
| 103 | +// For custom tools, you can define them directly |
| 104 | +const customTool = { |
| 105 | + name: 'findCompany', |
| 106 | + description: 'Find information about a company by name', |
| 107 | + parameters: { |
| 108 | + type: 'object', |
| 109 | + properties: { |
| 110 | + companyName: { |
| 111 | + type: 'string', |
| 112 | + description: 'The name of the company' |
| 113 | + } |
| 114 | + }, |
| 115 | + required: ['companyName'] |
| 116 | + } |
| 117 | +}; |
| 118 | + |
| 119 | +// Add the custom tool to the agent |
| 120 | +researchAgent.data.tools.push(customTool); |
| 121 | + |
| 122 | +// Add to workflow |
| 123 | +workflow.addBlock(researchAgent); |
| 124 | + |
| 125 | +// Connect to starter |
| 126 | +const starterBlock = workflow.getStarterBlock(); |
| 127 | +workflow.connect(starterBlock.id, researchAgent.id); |
| 128 | + |
| 129 | +// Build and save |
| 130 | +const builtWorkflow = workflow.build(); |
| 131 | +``` |
| 132 | + |
| 133 | +### Creating Conditional Workflows |
| 134 | + |
| 135 | +You can create workflows with conditional branching using the ConditionBlock: |
| 136 | + |
| 137 | +```typescript |
| 138 | +import { SimStudio, AgentBlock, ConditionBlock } from '@sim-studio/sdk'; |
| 139 | + |
| 140 | +// Create a condition block |
| 141 | +const conditionBlock = new ConditionBlock({ |
| 142 | + conditions: [ |
| 143 | + { expression: 'input.score > 0.8', id: 'high' }, |
| 144 | + { expression: 'input.score > 0.5', id: 'medium' }, |
| 145 | + { expression: 'true', id: 'low' } |
| 146 | + ] |
| 147 | +}); |
| 148 | + |
| 149 | +// Connect condition outcomes to different blocks |
| 150 | +workflow.connect( |
| 151 | + conditionBlock.id, |
| 152 | + highQualityBlock.id, |
| 153 | + { sourceHandle: 'condition-high' } |
| 154 | +); |
| 155 | + |
| 156 | +workflow.connect( |
| 157 | + conditionBlock.id, |
| 158 | + mediumQualityBlock.id, |
| 159 | + { sourceHandle: 'condition-medium' } |
| 160 | +); |
| 161 | + |
| 162 | +workflow.connect( |
| 163 | + conditionBlock.id, |
| 164 | + lowQualityBlock.id, |
| 165 | + { sourceHandle: 'condition-low' } |
| 166 | +); |
| 167 | +``` |
| 168 | + |
| 169 | +## API Reference |
| 170 | + |
| 171 | +### SimStudio |
| 172 | + |
| 173 | +- `createWorkflow(name, description?)`: Creates a new workflow builder |
| 174 | +- `saveWorkflow(workflow)`: Saves a workflow and returns the saved workflow with ID |
| 175 | +- `deployWorkflow(workflowId, options?)`: Deploys a workflow |
| 176 | +- `executeWorkflow(workflowId, input)`: Executes a workflow with the given input |
| 177 | + |
| 178 | +### WorkflowBuilder |
| 179 | + |
| 180 | +- `addBlock(block)`: Adds a block to the workflow |
| 181 | +- `connect(sourceId, targetId, options?)`: Connects two blocks |
| 182 | +- `getStarterBlock()`: Gets the starter block |
| 183 | +- `build()`: Builds the workflow |
| 184 | + |
| 185 | +### Block Types |
| 186 | + |
| 187 | +- `AgentBlock`: Agent that can generate content using LLMs |
| 188 | +- `FunctionBlock`: Executes JavaScript code |
| 189 | +- `ConditionBlock`: Routes based on conditions |
| 190 | +- `RouterBlock`: Routes based on agent decisions |
| 191 | +- `ApiBlock`: Makes HTTP requests |
| 192 | +- `EvaluatorBlock`: Evaluates content quality |
| 193 | + |
| 194 | +## Examples |
| 195 | + |
| 196 | +See the [examples](./examples) directory for more examples of using the SDK. |
| 197 | + |
| 198 | +## Features |
| 199 | + |
| 200 | +- Create and manage workflows programmatically |
| 201 | +- Build complex workflows with various block types |
| 202 | +- Execute workflows and retrieve results |
| 203 | +- Deploy workflows as API endpoints |
| 204 | +- Schedule workflows for automatic execution |
| 205 | + |
| 206 | +## Block Types |
| 207 | + |
| 208 | +The SDK supports all Sim Studio block types: |
| 209 | + |
| 210 | +- **Agent**: LLM-powered operations |
| 211 | +- **Function**: Custom JavaScript code execution |
| 212 | +- **Condition**: Branching based on logical expressions |
| 213 | +- **Router**: Dynamic path selection |
| 214 | +- **API**: HTTP requests |
| 215 | +- **Evaluator**: LLM-based output assessment |
| 216 | + |
| 217 | +## Documentation |
| 218 | + |
| 219 | +For detailed documentation, visit [docs.simstudio.dev](https://docs.simstudio.dev) |
| 220 | + |
| 221 | +## License |
| 222 | + |
| 223 | +MIT |
0 commit comments