Skip to content

Commit fbb164d

Browse files
improvement(copilot): add best practices for core blocks (#1427)
* improvement(copilot): add best practices for blocks * fix kb, api * Update apps/sim/blocks/blocks/memory.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * address comments * remove non deterministic test --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent dd8f633 commit fbb164d

File tree

18 files changed

+86
-26
lines changed

18 files changed

+86
-26
lines changed

apps/sim/app/api/workflows/[id]/variables/route.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,6 @@ describe('Workflow Variables API Route', () => {
179179
expect(response.headers.get('Cache-Control')).toBe('max-age=30, stale-while-revalidate=300')
180180
expect(response.headers.get('ETag')).toMatch(/^"variables-workflow-123-\d+"$/)
181181
})
182-
183-
it.concurrent('should return empty object for workflows with no variables', async () => {
184-
const mockWorkflow = {
185-
id: 'workflow-123',
186-
userId: 'user-123',
187-
workspaceId: null,
188-
variables: null,
189-
}
190-
191-
authMocks.setAuthenticated({ id: 'user-123', email: '[email protected]' })
192-
databaseMocks = createMockDatabase({
193-
select: { results: [[mockWorkflow]] },
194-
})
195-
196-
const req = new NextRequest('http://localhost:3000/api/workflows/workflow-123/variables')
197-
const params = Promise.resolve({ id: 'workflow-123' })
198-
199-
const { GET } = await import('@/app/api/workflows/[id]/variables/route')
200-
const response = await GET(req, { params })
201-
202-
expect(response.status).toBe(200)
203-
const data = await response.json()
204-
expect(data.data).toEqual({})
205-
})
206182
})
207183

208184
describe('POST /api/workflows/[id]/variables', () => {

apps/sim/blocks/blocks/agent.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
6565
authMode: AuthMode.ApiKey,
6666
longDescription:
6767
'The Agent block is a core workflow block that is a wrapper around an LLM. It takes in system/user prompts and calls an LLM provider. It can also make tool calls by directly containing tools inside of its tool input. It can additionally return structured output.',
68+
bestPractices: `
69+
- Cannot use core blocks like API, Webhook, Function, Workflow, Memory as tools. Only integrations or custom tools.
70+
- Check custom tools examples for YAML syntax. Only construct these if there isn't an existing integration for that purpose.
71+
- Response Format should be a valid JSON Schema. This determines the output of the agent only if present. Fields can be accessed at root level by the following blocks: e.g. <agent1.field>. If response format is not present, the agent will return the standard outputs: content, model, tokens, toolCalls.
72+
`,
6873
docsLink: 'https://docs.sim.ai/blocks/agent',
6974
category: 'blocks',
7075
bgColor: 'var(--brand-primary-hex)',

apps/sim/blocks/blocks/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const ApiBlock: BlockConfig<RequestResponse> = {
99
longDescription:
1010
'This is a core workflow block. Connect to any external API with support for all standard HTTP methods and customizable request parameters. Configure headers, query parameters, and request bodies. Standard headers (User-Agent, Accept, Cache-Control, etc.) are automatically included.',
1111
docsLink: 'https://docs.sim.ai/blocks/api',
12+
bestPractices: `
13+
- Curl the endpoint yourself before filling out the API block to make sure it's working IF you have the necessary authentication headers. Clarify with the user if you need any additional headers.
14+
`,
1215
category: 'blocks',
1316
bgColor: '#2F55FF',
1417
icon: ApiIcon,

apps/sim/blocks/blocks/api_trigger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export const ApiTriggerBlock: BlockConfig = {
77
description: 'Expose as HTTP API endpoint',
88
longDescription:
99
'API trigger to start the workflow via authenticated HTTP calls with structured input.',
10+
bestPractices: `
11+
- Can run the workflow manually to test implementation when this is the trigger point.
12+
- The input format determines variables accesssible in the following blocks. E.g. <api1.paramName>. You can set the value in the input format to test the workflow manually.
13+
- In production, the curl would come in as e.g. curl -X POST -H "X-API-Key: $SIM_API_KEY" -H "Content-Type: application/json" -d '{"paramName":"example"}' https://www.staging.sim.ai/api/workflows/9e7e4f26-fc5e-4659-b270-7ea474b14f4a/execute -- If user asks to test via API, you might need to clarify the API key.
14+
`,
1015
category: 'triggers',
1116
bgColor: '#2F55FF',
1217
icon: ApiIcon,

apps/sim/blocks/blocks/chat_trigger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const ChatTriggerBlock: BlockConfig = {
1010
name: 'Chat',
1111
description: 'Start workflow from a chat deployment',
1212
longDescription: 'Chat trigger to run the workflow via deployed chat interfaces.',
13+
bestPractices: `
14+
- Can run the workflow manually to test implementation when this is the trigger point by passing in a message.
15+
`,
1316
category: 'triggers',
1417
bgColor: '#6F3DFA',
1518
icon: ChatTriggerIcon,

apps/sim/blocks/blocks/condition.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const ConditionBlock: BlockConfig<ConditionBlockOutput> = {
2121
description: 'Add a condition',
2222
longDescription:
2323
'This is a core workflow block. Add a condition to the workflow to branch the execution path based on a boolean expression.',
24+
bestPractices: `
25+
- Write the conditions using standard javascript syntax except referencing the outputs of previous blocks using <> syntax, and keep them as simple as possible. No hacky fallbacks.
26+
- Can reference workflow variables using <blockName.output> syntax as usual within conditions.
27+
`,
2428
docsLink: 'https://docs.sim.ai/blocks/condition',
2529
bgColor: '#FF752F',
2630
icon: ConditionalIcon,

apps/sim/blocks/blocks/file.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
1010
name: 'File',
1111
description: 'Read and parse multiple files',
1212
longDescription: `Integrate File into the workflow. Can upload a file manually or insert a file url.`,
13+
bestPractices: `
14+
- You should always use the File URL input method and enter the file URL if the user gives it to you or clarify if they have one.
15+
`,
1316
docsLink: 'https://docs.sim.ai/tools/file',
1417
category: 'tools',
1518
bgColor: '#40916C',

apps/sim/blocks/blocks/function.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export const FunctionBlock: BlockConfig<CodeExecutionOutput> = {
99
description: 'Run custom logic',
1010
longDescription:
1111
'This is a core workflow block. Execute custom JavaScript or Python code within your workflow. Use E2B for remote execution with imports or enable Fast Mode (bolt) to run JavaScript locally for lowest latency.',
12+
bestPractices: `
13+
- If the user asks for Python, you should always use the Remote Code Execution switch and select Python.
14+
- If the user asks Javascript and you need imports, you should use the Remote Code Execution switch and select Javascript.
15+
- If the user asks for a simple function, don't turn on the Remote Code Execution switch and write it in javascript.
16+
- Can reference workflow variables using <blockName.output> syntax as usual within code. Avoid XML/HTML tags.
17+
`,
1218
docsLink: 'https://docs.sim.ai/blocks/function',
1319
category: 'blocks',
1420
bgColor: '#FF402F',
@@ -44,7 +50,7 @@ export const FunctionBlock: BlockConfig<CodeExecutionOutput> = {
4450
enabled: true,
4551
maintainHistory: true,
4652
prompt: `You are an expert JavaScript programmer.
47-
Generate ONLY the raw body of a JavaScript function based on the user's request.
53+
Generate ONLY the raw body of a JavaScript function based on the user's request. Never wrap in markdown formatting.
4854
The code should be executable within an 'async function(params, environmentVariables) {...}' context.
4955
- 'params' (object): Contains input parameters derived from the JSON schema. Access these directly using the parameter name wrapped in angle brackets, e.g., '<paramName>'. Do NOT use 'params.paramName'.
5056
- 'environmentVariables' (object): Contains environment variables. Reference these using the double curly brace syntax: '{{ENV_VAR_NAME}}'. Do NOT use 'environmentVariables.VAR_NAME' or env.

apps/sim/blocks/blocks/generic_webhook.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export const GenericWebhookBlock: BlockConfig = {
1313
icon: WebhookIcon,
1414
bgColor: '#10B981', // Green color for triggers
1515
triggerAllowed: true,
16-
16+
bestPractices: `
17+
- You can test the webhook by sending a request to the webhook URL. E.g. depending on authorization: curl -X POST http://localhost:3000/api/webhooks/trigger/d8abcf0d-1ee5-4b77-bb07-b1e8142ea4e9 -H "Content-Type: application/json" -H "X-Sim-Secret: 1234" -d '{"message": "Test webhook trigger", "data": {"key": "v"}}'
18+
- Continuing example above, the body can be accessed in downstream block using dot notation. E.g. <webhook1.message> and <webhook1.data.key>
19+
- Only use when there's no existing integration for the service with triggerAllowed flag set to true.
20+
`,
1721
subBlocks: [
1822
// Generic webhook configuration - always visible
1923
{

apps/sim/blocks/blocks/input_trigger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export const InputTriggerBlock: BlockConfig = {
1111
description: 'Start workflow manually with a defined input schema',
1212
longDescription:
1313
'Manually trigger the workflow from the editor with a structured input schema. This enables typed inputs for parent workflows to map into.',
14+
bestPractices: `
15+
- Can run the workflow manually to test implementation when this is the trigger point.
16+
- The input format determines variables accesssible in the following blocks. E.g. <input1.paramName>. You can set the value in the input format to test the workflow manually.
17+
- Also used in child workflows to map variables from the parent workflow.
18+
`,
1419
category: 'triggers',
1520
bgColor: '#3B82F6',
1621
icon: InputTriggerIcon,

0 commit comments

Comments
 (0)