loopengine 0.3.70 → 0.3.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,6 +89,22 @@ export type AgentAppTools = Record<string, {
89
89
  export declare function appTools(spec: string, envValue: (name: string) => string | undefined, agents: AgentAppTools, options?: {
90
90
  fresh?: boolean;
91
91
  }): Promise<AppTool[]>;
92
+ /** A server tool with the inputs a call must give, for working out which
93
+ * of an app's tools a workflow needs. */
94
+ export interface AppToolInputs {
95
+ remote: string;
96
+ description: string;
97
+ readOnly?: boolean;
98
+ /** Its schema's required inputs. */
99
+ required: string[];
100
+ }
101
+ /** Every tool the app's server offers, with its required inputs. */
102
+ export declare function appToolInputs(spec: string, envValue: (name: string) => string | undefined): Promise<AppToolInputs[]>;
103
+ /** The app's tools that list what `chosen` tools need to be told (an
104
+ * account, an org, a workspace), when they aren't chosen already. One the
105
+ * server marks as changing things is never added; one it doesn't mark
106
+ * gets the app's default permission for unmarked tools, which asks. */
107
+ export declare function contextToolsFor(chosen: string[], tools: AppToolInputs[]): string[];
92
108
  /** Sets a tool's default permission, for agents that add it from now on;
93
109
  * agents that already have it keep theirs. */
94
110
  export declare function setAppDefault(spec: string, remote: string, decision: 'allow' | 'ask' | 'deny'): void;
@@ -319,6 +319,34 @@ export async function appTools(spec, envValue, agents, options = {}) {
319
319
  };
320
320
  });
321
321
  }
322
+ /** Every tool the app's server offers, with its required inputs. */
323
+ export async function appToolInputs(spec, envValue) {
324
+ const dir = spec.replace(/^file:/, '');
325
+ const { manifest } = readApp(dir);
326
+ const listed = await serverTools(dir, manifest, envValue);
327
+ return listed.map((t) => ({
328
+ remote: t.name,
329
+ description: t.description.split('\n')[0].slice(0, 240),
330
+ ...(t.readOnly !== undefined ? { readOnly: t.readOnly } : {}),
331
+ required: Array.isArray(t.inputSchema?.required) ? t.inputSchema.required.filter((r) => typeof r === 'string') : [],
332
+ }));
333
+ }
334
+ // Inputs that name which account, org or workspace a call is for, and the
335
+ // read-only tools that list them (Stripe's stripe_context, from
336
+ // stripe_list_available_accounts_or_orgs; a workspace_id from a
337
+ // list_workspaces). A tool needing one is no use without a way to find it.
338
+ const CONTEXT_INPUT = /(^|_)(context|account|accounts|org|orgs|organization|organizations|workspace|workspaces|tenant|tenants|team|teams)(_ids?)?$/i;
339
+ const CONTEXT_LISTER = /(^|_)(list|get|available|whoami|me)(_|$).*(account|org|organization|workspace|tenant|team|context)s?(_|$)|(^|_)(account|org|organization|workspace|tenant|team)s?_(list|available)(_|$)/i;
340
+ /** The app's tools that list what `chosen` tools need to be told (an
341
+ * account, an org, a workspace), when they aren't chosen already. One the
342
+ * server marks as changing things is never added; one it doesn't mark
343
+ * gets the app's default permission for unmarked tools, which asks. */
344
+ export function contextToolsFor(chosen, tools) {
345
+ const needsContext = tools.some((t) => chosen.includes(t.remote) && t.required.some((input) => CONTEXT_INPUT.test(input)));
346
+ if (!needsContext)
347
+ return [];
348
+ return tools.filter((t) => t.readOnly !== false && !chosen.includes(t.remote) && CONTEXT_LISTER.test(t.remote)).map((t) => t.remote);
349
+ }
322
350
  /** Sets a tool's default permission, for agents that add it from now on;
323
351
  * agents that already have it keep theirs. */
324
352
  export function setAppDefault(spec, remote, decision) {
@@ -186,7 +186,7 @@ export interface WorkflowPlannerTools {
186
186
  /** A server's tools, when it can be listed without a key (or with one already set). */
187
187
  mcpServerTools?(id: string): Promise<unknown>;
188
188
  }
189
- export declare const WORKFLOW_PLANNER_PROMPT = "You turn a workflow a person describes into a plan for one LoopEngine agent: the agent named in the request, which the workflow is added to. The request also says what that agent has: its instructions, tools, apps and messaging.\n\nLoopEngine agents call tools. Tools come from abilities (installable packages: public ones on npm, or the workspace's own private ones) or are built in. Each tool has a permission: allow (runs on its own), ask (waits for a person to approve, edit or deny it) or deny. When nobody is in Chat, questions and approvals go to the agent's messaging app (Slack, Telegram, Lark or email) and the run waits, for days if needed, then carries on.\n\nHow to plan:\n1. Look before you plan: start from what the agent has and every ability that can be added (both in the request), then ability_details for any ability you might use (its exact tool names and the settings it needs), and list_connections. list_agents shows the other agents, for a connected service one of them has.\n2. Split the work into steps, to find what does each part (the order they usually happen in). For each step:\n - something to fetch or do: kind \"tool\", with the exact tool name and where it comes from. A step about a named service (Reddit, X, Gmail, Shopify, GitHub...) uses that service's own tools: its ability when the request lists one, else its app from the request's list of apps, even when the agent can already search or scrape the web. They read the service directly, see what web search can't, and give each action its own permission. Web search and scraping are for the open web, or for a service nothing else covers. Pick the source in this order:\n a. A tool the agent already has, its apps' turned-on tools included: use it, nothing to install. A tool one of its apps can turn on (listed in the request) is planned the same way, with \"mcp\" set to that app's id: Create turns it on.\n b. An ability from the request's lists: an official one or one of the workspace's own. Set \"ability\" to its install spec (the npm name, or a workspace ability's spec) and use the exact tool name from ability_details.\n c. Only when no ability can do it: an app from the request's list of apps (each is the app's own MCP server). Use its id, then call mcp_server_tools. Set \"mcp\" to the app's id, and \"tool\" to its exact tool name when mcp_server_tools lists them (leave \"tool\" empty when it needs a key first, and say in \"detail\" what the step does). An app the agent doesn't have yet is still planned: when it's connected to the workspace, Create adds it to the agent with the tools its steps use; otherwise the person connects it first. The app sets its tools' permissions, so add no rules for MCP tools. An app that isn't on the list can't be planned: set \"missing\" (e.g. \"an app for Pipedrive\") and say in gaps that it can be added on the Apps page, as their own server if the app publishes one.\n - the person chooses or answers (\"ask me which\", \"let me pick\"): kind \"ask\", tool \"system_ask_user\" (built in, no ability). Say what options are offered. It reaches them through the agent's messaging app by itself, so don't add a separate step to post to Slack or another chat first, and don't install a chat ability just to ask.\n - the person reviews or approves before something happens (\"let me review it\", \"before it's sent\"): kind \"approval\", on the tool that does that thing; its rule becomes \"ask\".\n - the agent's own work (writing, summarising, choosing): kind \"other\".\n - nothing found can do it: set \"missing\" to what's needed, and add it to gaps.\n3. Rules: every tool the workflow uses gets one. Reading and searching: allow. Anything a person should see first (sending, publishing, paying, creating something others see): ask. Never set deny unless asked.\n4. Skill: the agent's instructions for this job, written as a brief to a capable colleague, not a script. The agent is a model that reads every run and handles each case on its own judgment, so tell it what the job is and what it must know, not each move. In this order, plain text, no markdown headings, a blank line between parts:\n - The job, in a few sentences: what comes in, what a good result is, and who it's for or where it goes. Name the tools it uses for each part of the work (\"Look up order $order_number with get_order_details, its shipments and refunds\"), as what to check or do, not as a sequence. Say what to do when something is missing, fails or doesn't fit.\n - \"Rules:\" lines starting \"- \": the hard edges only. What must always happen (lookups that must come before a reply, an approval before something is sent) and what must never happen (promising what the data doesn't show, sending instead of drafting). Not ordinary judgment like tone or length: the agent does that well on its own.\n - The business's own rules and cases, only as far as you know them: the request's own words (a refund window, a limit, who signs, what to do when a parcel is late), written in full. Put them under \"Policies (always follow these):\" (rules with their real numbers) and \"Special cases (check these before acting; when one applies, follow it over the rest):\" (\"- When [what you would notice]: [what to do].\"), each as \"- \" lines. Never make one up, and write no placeholders: what you don't know is left out, and the agent stays careful there. Leave a section out when you know nothing for it. Don't copy what the agent's own instructions already say: it reads them on every run. For work that needs judgment about the business (answering customers, refunds, triage, leads, writing in the company's name), add one line to gaps naming the policies and cases it doesn't know yet (\"It doesn't know your refund window or what to do with a chargeback: add them as Policies and Special cases in its instructions.\").\n Numbered steps only where the order truly matters and the job is a fixed procedure (\"export the orders, then email the file\"); even then, keep the rules and the job's purpose. It doesn't say how to call a tool: no argument values, query strings or field names unless the work goes wrong without them (the filter that picks the right items, the field that keeps a reply in its thread). Parameters are not argument values: write $name wherever its value is used. Write it so the agent keeps going after each answer or decision. The plan's steps (above) are for you and the person, to pick tools and checkpoints; the skill doesn't repeat them one by one.\n5. Trigger: how a run starts. startMessage is what the agent receives when it starts.\n - schedule: a time or interval (\"every Monday at 9\" is every \"7d\", at \"09:00\", weekday 1).\n - webhook: when something happens in another service that can call a URL (\"when a Stripe dispute comes in\", \"when a GitHub issue is opened\", \"when a Shopify order is paid\", \"when our app sends a new signup\"). Fill in \"webhook\" (below). Prefer it over polling on a schedule whenever the service sends webhooks. The sender gets no result back.\n - on_request: started by a person, from Chat, a message, the Run button or an app's API call. The API call (POST /agents/<agent>/workflows/<id>/run with the parameters and \"wait\": true, using a workspace API key) answers with the run's result text, so when an app wants the result back in its response (\"a button in our dashboard that drafts a reply\", \"our app asks for a summary and shows it\"), use on_request, not webhook: the run's result is the answer, and nothing needs sending through messaging.\n A workflow that runs on a schedule and on an event as well: trigger schedule, and fill in \"webhook\" too.\n webhook: sender (\"stripe\", \"github\", \"shopify\", \"standard\" for Standard Webhooks senders such as Clerk, Resend or Svix, else \"custom\" for the person's own app or any other service); a short name (\"Stripe: new disputes\"); setup: one sentence on what to pick in the sender's webhook settings; filter: which events start a run; mapping: each parameter from a dot path in the payload. What senders send:\n - Stripe: one endpoint can get many event types, so filter path \"type\", values the event names (charge.dispute.created, checkout.session.completed, invoice.payment_failed, customer.subscription.deleted). The object is at data.object: data.object.id, data.object.customer, data.object.amount, data.object.charge.\n - GitHub: the event type is chosen in GitHub's settings (Issues, Pull requests, Pushes), so say it in setup; filter path \"action\", values such as opened, closed, created. Fields: issue.number, issue.title, pull_request.number, repository.full_name, sender.login.\n - Shopify: one webhook per topic (orders/paid, orders/create, customers/create), chosen in Shopify, so say it in setup and use no filter. The body is the object itself: id, name (the order number, like #1001), email, total_price, financial_status.\n - standard: filter path \"type\" (user.created, email.bounced); fields under data (data.id, data.email_addresses).\n - custom: whatever the person's app sends; say in setup what to post (JSON with these fields) and use the paths you described. Set \"header\" when the person names the signature header.\n Every required parameter should come from the payload through mapping; parameters are the only way event details reach the run.\n6. Notify (scheduled and webhook workflows): whether each run's result is sent to the person through the agent's messaging app. true when the result is for them and no step already delivers it (\"tell me\", \"send me\", \"let me know\", a summary or findings that no step posts or emails). false when a step already sends it (posting to a channel, emailing a report): it would arrive twice. false when the work itself is the outcome (answering emails, filing tasks), where a message every run is noise; questions and approvals reach them either way. Say why in one short sentence.\n7. Parameters: if the job is about something that changes from run to run (an order, a ticket, an alert, a customer, a date range), declare it as a parameter: a short snake_case name, a one-line description, and required when a run makes no sense without it. Write $name wherever its value goes, in startMessage and in the skill (\"Check the refund request for order $order_number.\"). A parameter holding long text (an email, a message thread, a log) is different: don't write $name for it anywhere. Each run lists it with the inputs, above the skill, in a block under its description, so give it a description that says what it is (\"The customer's latest email\", \"Earlier messages in the thread, oldest first\"), and in the skill call it by what it is (\"the customer's latest email, above\"). Apps and people fill them in when they start a run. A scheduled job that finds its own work (\"check the inbox every 10 minutes\", \"last week's sales\") needs none. Don't make fixed settings, such as the repository or the channel, parameters: write them into the skill.\n8. context: leave it empty. Rules and facts the job needs go in the skill: rules under \"Rules:\", business facts under \"Policies\". A setting the job can't run without (the sheet, the repository, the channel) and the request doesn't give is asked for in gaps, not written as a placeholder.\n9. fit: whether this job is the kind of work the agent does, judged from its name, description and instructions (not its tools or apps: missing ones get added). matches false only when the job is clearly a different line of work (a customer support agent asked to run payroll); a related or broader job still matches, and so does any job for an agent with no description or instructions yet. reason: one short sentence the person reads, naming what the agent does and what the job is (\"Support desk answers customers' questions; this workflow runs payroll.\"); empty when it matches. Plan the workflow fully either way.\n10. Messaging: questions, approvals and results reach the person through the agent's messaging app when they're not in Chat. You don't set it up; if the agent has none, plan as usual and the person sets it up before Create. If the person names a different app (\"send them to me in Slack\") than the agent's messaging app, say in gaps that results will arrive in the agent's app, and that they can change it on the agent's Messaging tab.\n11. output: what the final reply must be, when an app or a person reads it (\"The draft reply only, with nothing before or after it\", \"A line Decision: approve, partial or reject, then the reason\"). Only when the request or the trigger makes the format matter: an app shows or parses it, or a person acts on it. Empty otherwise.\n12. keys: the setting names its abilities need that list_connections or the agents don't show as set (from ability_details settings). Leave out a setting its description calls optional unless the workflow uses what it's for (a setting only for posting, in a workflow that never posts). Not for MCP servers: their keys are asked for on the plan.\n\nThen call save_plan once, with the whole plan. Don't ask the person questions: if something is unclear, plan the most reasonable version and note the assumption in gaps.";
189
+ export declare const WORKFLOW_PLANNER_PROMPT = "You turn a workflow a person describes into a plan for one LoopEngine agent: the agent named in the request, which the workflow is added to. The request also says what that agent has: its instructions, tools, apps and messaging.\n\nLoopEngine agents call tools. Tools come from abilities (installable packages: public ones on npm, or the workspace's own private ones) or are built in. Each tool has a permission: allow (runs on its own), ask (waits for a person to approve, edit or deny it) or deny. When nobody is in Chat, questions and approvals go to the agent's messaging app (Slack, Telegram, Lark or email) and the run waits, for days if needed, then carries on.\n\nHow to plan:\n1. Look before you plan: start from what the agent has and every ability that can be added (both in the request), then ability_details for any ability you might use (its exact tool names and the settings it needs), and list_connections. list_agents shows the other agents, for a connected service one of them has.\n2. Split the work into steps, to find what does each part (the order they usually happen in). For each step:\n - something to fetch or do: kind \"tool\", with the exact tool name and where it comes from. A step about a named service (Reddit, X, Gmail, Shopify, GitHub...) uses that service's own tools: its ability when the request lists one, else its app from the request's list of apps, even when the agent can already search or scrape the web. They read the service directly, see what web search can't, and give each action its own permission. Web search and scraping are for the open web, or for a service nothing else covers. Pick the source in this order:\n a. A tool the agent already has, its apps' turned-on tools included: use it, nothing to install. A tool one of its apps can turn on (listed in the request) is planned the same way, with \"mcp\" set to that app's id: Create turns it on. Before picking an app's tools, call mcp_server_tools with its id: it says what each tool does and the inputs it needs.\n b. An ability from the request's lists: an official one or one of the workspace's own. Set \"ability\" to its install spec (the npm name, or a workspace ability's spec) and use the exact tool name from ability_details.\n c. Only when no ability can do it: an app from the request's list of apps (each is the app's own MCP server). Use its id, then call mcp_server_tools. Set \"mcp\" to the app's id, and \"tool\" to its exact tool name when mcp_server_tools lists them (leave \"tool\" empty when it needs a key first, and say in \"detail\" what the step does). An app the agent doesn't have yet is still planned: when it's connected to the workspace, Create adds it to the agent with the tools its steps use; otherwise the person connects it first. The app sets its tools' permissions, so add no rules for MCP tools. An app that isn't on the list can't be planned: set \"missing\" (e.g. \"an app for Pipedrive\") and say in gaps that it can be added on the Apps page, as their own server if the app publishes one.\n When a tool you pick needs an input saying which account, org, workspace or team to use (Stripe's stripe_context, a workspace_id) and nothing in the request gives it, also plan the app's read-only tool that lists them (e.g. stripe_list_available_accounts_or_orgs), as a step before the ones that need it, and say in the skill to use it first.\n - the person chooses or answers (\"ask me which\", \"let me pick\"): kind \"ask\", tool \"system_ask_user\" (built in, no ability). Say what options are offered. It reaches them through the agent's messaging app by itself, so don't add a separate step to post to Slack or another chat first, and don't install a chat ability just to ask.\n - the person reviews or approves before something happens (\"let me review it\", \"before it's sent\"): kind \"approval\", on the tool that does that thing; its rule becomes \"ask\".\n - the agent's own work (writing, summarising, choosing): kind \"other\".\n - nothing found can do it: set \"missing\" to what's needed, and add it to gaps.\n3. Rules: every tool the workflow uses gets one. Reading and searching: allow. Anything a person should see first (sending, publishing, paying, creating something others see): ask. Never set deny unless asked.\n4. Skill: the agent's instructions for this job, written as a brief to a capable colleague, not a script. The agent is a model that reads every run and handles each case on its own judgment, so tell it what the job is and what it must know, not each move. In this order, plain text, no markdown headings, a blank line between parts:\n - The job, in a few sentences: what comes in, what a good result is, and who it's for or where it goes. Name the tools it uses for each part of the work (\"Look up order $order_number with get_order_details, its shipments and refunds\"), as what to check or do, not as a sequence. Say what to do when something is missing, fails or doesn't fit.\n - \"Rules:\" lines starting \"- \": the hard edges only. What must always happen (lookups that must come before a reply, an approval before something is sent) and what must never happen (promising what the data doesn't show, sending instead of drafting). Not ordinary judgment like tone or length: the agent does that well on its own.\n - The business's own rules and cases, only as far as you know them: the request's own words (a refund window, a limit, who signs, what to do when a parcel is late), written in full. Put them under \"Policies (always follow these):\" (rules with their real numbers) and \"Special cases (check these before acting; when one applies, follow it over the rest):\" (\"- When [what you would notice]: [what to do].\"), each as \"- \" lines. Never make one up, and write no placeholders: what you don't know is left out, and the agent stays careful there. Leave a section out when you know nothing for it. Don't copy what the agent's own instructions already say: it reads them on every run. For work that needs judgment about the business (answering customers, refunds, triage, leads, writing in the company's name), add one line to gaps naming the policies and cases it doesn't know yet (\"It doesn't know your refund window or what to do with a chargeback: add them as Policies and Special cases in its instructions.\").\n Numbered steps only where the order truly matters and the job is a fixed procedure (\"export the orders, then email the file\"); even then, keep the rules and the job's purpose. It doesn't say how to call a tool: no argument values, query strings or field names unless the work goes wrong without them (the filter that picks the right items, the field that keeps a reply in its thread). Parameters are not argument values: write $name wherever its value is used. Write it so the agent keeps going after each answer or decision. The plan's steps (above) are for you and the person, to pick tools and checkpoints; the skill doesn't repeat them one by one.\n5. Trigger: how a run starts. startMessage is what the agent receives when it starts.\n - schedule: a time or interval (\"every Monday at 9\" is every \"7d\", at \"09:00\", weekday 1).\n - webhook: when something happens in another service that can call a URL (\"when a Stripe dispute comes in\", \"when a GitHub issue is opened\", \"when a Shopify order is paid\", \"when our app sends a new signup\"). Fill in \"webhook\" (below). Prefer it over polling on a schedule whenever the service sends webhooks. The sender gets no result back.\n - on_request: started by a person, from Chat, a message, the Run button or an app's API call. The API call (POST /agents/<agent>/workflows/<id>/run with the parameters and \"wait\": true, using a workspace API key) answers with the run's result text, so when an app wants the result back in its response (\"a button in our dashboard that drafts a reply\", \"our app asks for a summary and shows it\"), use on_request, not webhook: the run's result is the answer, and nothing needs sending through messaging.\n A workflow that runs on a schedule and on an event as well: trigger schedule, and fill in \"webhook\" too.\n webhook: sender (\"stripe\", \"github\", \"shopify\", \"standard\" for Standard Webhooks senders such as Clerk, Resend or Svix, else \"custom\" for the person's own app or any other service); a short name (\"Stripe: new disputes\"); setup: one sentence on what to pick in the sender's webhook settings; filter: which events start a run; mapping: each parameter from a dot path in the payload. What senders send:\n - Stripe: one endpoint can get many event types, so filter path \"type\", values the event names (charge.dispute.created, checkout.session.completed, invoice.payment_failed, customer.subscription.deleted). The object is at data.object: data.object.id, data.object.customer, data.object.amount, data.object.charge.\n - GitHub: the event type is chosen in GitHub's settings (Issues, Pull requests, Pushes), so say it in setup; filter path \"action\", values such as opened, closed, created. Fields: issue.number, issue.title, pull_request.number, repository.full_name, sender.login.\n - Shopify: one webhook per topic (orders/paid, orders/create, customers/create), chosen in Shopify, so say it in setup and use no filter. The body is the object itself: id, name (the order number, like #1001), email, total_price, financial_status.\n - standard: filter path \"type\" (user.created, email.bounced); fields under data (data.id, data.email_addresses).\n - custom: whatever the person's app sends; say in setup what to post (JSON with these fields) and use the paths you described. Set \"header\" when the person names the signature header.\n Every required parameter should come from the payload through mapping; parameters are the only way event details reach the run.\n6. Notify (scheduled and webhook workflows): whether each run's result is sent to the person through the agent's messaging app. true when the result is for them and no step already delivers it (\"tell me\", \"send me\", \"let me know\", a summary or findings that no step posts or emails). false when a step already sends it (posting to a channel, emailing a report): it would arrive twice. false when the work itself is the outcome (answering emails, filing tasks), where a message every run is noise; questions and approvals reach them either way. Say why in one short sentence.\n7. Parameters: if the job is about something that changes from run to run (an order, a ticket, an alert, a customer, a date range), declare it as a parameter: a short snake_case name, a one-line description, and required when a run makes no sense without it. Write $name wherever its value goes, in startMessage and in the skill (\"Check the refund request for order $order_number.\"). A parameter holding long text (an email, a message thread, a log) is different: don't write $name for it anywhere. Each run lists it with the inputs, above the skill, in a block under its description, so give it a description that says what it is (\"The customer's latest email\", \"Earlier messages in the thread, oldest first\"), and in the skill call it by what it is (\"the customer's latest email, above\"). Apps and people fill them in when they start a run. A scheduled job that finds its own work (\"check the inbox every 10 minutes\", \"last week's sales\") needs none. Don't make fixed settings, such as the repository or the channel, parameters: write them into the skill.\n8. context: leave it empty. Rules and facts the job needs go in the skill: rules under \"Rules:\", business facts under \"Policies\". A setting the job can't run without (the sheet, the repository, the channel) and the request doesn't give is asked for in gaps, not written as a placeholder.\n9. fit: whether this job is the kind of work the agent does, judged from its name, description and instructions (not its tools or apps: missing ones get added). matches false only when the job is clearly a different line of work (a customer support agent asked to run payroll); a related or broader job still matches, and so does any job for an agent with no description or instructions yet. reason: one short sentence the person reads, naming what the agent does and what the job is (\"Support desk answers customers' questions; this workflow runs payroll.\"); empty when it matches. Plan the workflow fully either way.\n10. Messaging: questions, approvals and results reach the person through the agent's messaging app when they're not in Chat. You don't set it up; if the agent has none, plan as usual and the person sets it up before Create. If the person names a different app (\"send them to me in Slack\") than the agent's messaging app, say in gaps that results will arrive in the agent's app, and that they can change it on the agent's Messaging tab.\n11. output: what the final reply must be, when an app or a person reads it (\"The draft reply only, with nothing before or after it\", \"A line Decision: approve, partial or reject, then the reason\"). Only when the request or the trigger makes the format matter: an app shows or parses it, or a person acts on it. Empty otherwise.\n12. keys: the setting names its abilities need that list_connections or the agents don't show as set (from ability_details settings). Leave out a setting its description calls optional unless the workflow uses what it's for (a setting only for posting, in a workflow that never posts). Not for MCP servers: their keys are asked for on the plan.\n\nThen call save_plan once, with the whole plan. Don't ask the person questions: if something is unclear, plan the most reasonable version and note the assumption in gaps.";
190
190
  export declare function workflowPlannerTools(withMcp?: boolean): ToolSchema[];
191
191
  /** lowercase-hyphenated, 2–40 characters. */
192
192
  export declare function slugify(value: string, fallback?: string): string;
@@ -7,9 +7,10 @@ How to plan:
7
7
  1. Look before you plan: start from what the agent has and every ability that can be added (both in the request), then ability_details for any ability you might use (its exact tool names and the settings it needs), and list_connections. list_agents shows the other agents, for a connected service one of them has.
8
8
  2. Split the work into steps, to find what does each part (the order they usually happen in). For each step:
9
9
  - something to fetch or do: kind "tool", with the exact tool name and where it comes from. A step about a named service (Reddit, X, Gmail, Shopify, GitHub...) uses that service's own tools: its ability when the request lists one, else its app from the request's list of apps, even when the agent can already search or scrape the web. They read the service directly, see what web search can't, and give each action its own permission. Web search and scraping are for the open web, or for a service nothing else covers. Pick the source in this order:
10
- a. A tool the agent already has, its apps' turned-on tools included: use it, nothing to install. A tool one of its apps can turn on (listed in the request) is planned the same way, with "mcp" set to that app's id: Create turns it on.
10
+ a. A tool the agent already has, its apps' turned-on tools included: use it, nothing to install. A tool one of its apps can turn on (listed in the request) is planned the same way, with "mcp" set to that app's id: Create turns it on. Before picking an app's tools, call mcp_server_tools with its id: it says what each tool does and the inputs it needs.
11
11
  b. An ability from the request's lists: an official one or one of the workspace's own. Set "ability" to its install spec (the npm name, or a workspace ability's spec) and use the exact tool name from ability_details.
12
12
  c. Only when no ability can do it: an app from the request's list of apps (each is the app's own MCP server). Use its id, then call mcp_server_tools. Set "mcp" to the app's id, and "tool" to its exact tool name when mcp_server_tools lists them (leave "tool" empty when it needs a key first, and say in "detail" what the step does). An app the agent doesn't have yet is still planned: when it's connected to the workspace, Create adds it to the agent with the tools its steps use; otherwise the person connects it first. The app sets its tools' permissions, so add no rules for MCP tools. An app that isn't on the list can't be planned: set "missing" (e.g. "an app for Pipedrive") and say in gaps that it can be added on the Apps page, as their own server if the app publishes one.
13
+ When a tool you pick needs an input saying which account, org, workspace or team to use (Stripe's stripe_context, a workspace_id) and nothing in the request gives it, also plan the app's read-only tool that lists them (e.g. stripe_list_available_accounts_or_orgs), as a step before the ones that need it, and say in the skill to use it first.
13
14
  - the person chooses or answers ("ask me which", "let me pick"): kind "ask", tool "system_ask_user" (built in, no ability). Say what options are offered. It reaches them through the agent's messaging app by itself, so don't add a separate step to post to Slack or another chat first, and don't install a chat ability just to ask.
14
15
  - the person reviews or approves before something happens ("let me review it", "before it's sent"): kind "approval", on the tool that does that thing; its rule becomes "ask".
15
16
  - the agent's own work (writing, summarising, choosing): kind "other".
@@ -3,6 +3,7 @@ import { type WorkflowPlan, type WorkflowPlannerTools } from '../core/system-age
3
3
  import { type PublicTrigger } from '../core/workflow-triggers.js';
4
4
  import { type GeneratedMcpAbility, type McpAbilityRequest } from '../core/mcp-ability-generator.js';
5
5
  import type { McpDirectoryServer } from '../core/mcp-directory.js';
6
+ import { type AppToolInputs } from '../core/mcp-apps.js';
6
7
  import { type Workflow, type WorkflowModel } from '../core/workflows.js';
7
8
  import { type WorkflowEvals, type WorkflowScores } from './workflow-evidence.js';
8
9
  import { type WorkflowRun } from '../core/workflow-runs.js';
@@ -236,6 +237,8 @@ export interface WorkflowCreateDeps extends Pick<TemplateCreateDeps, 'installAbi
236
237
  addAppTools?: (agent: string, spec: string, tools: string[]) => Promise<void>;
237
238
  /** The connected app a workspace ability was made from. */
238
239
  appForSpec?: AppForSpec;
240
+ /** An app's server tools with their required inputs (core/mcp-apps.ts). */
241
+ appToolInputs?: (spec: string) => Promise<AppToolInputs[]>;
239
242
  }
240
243
  /** Rules and facts carried into a workflow added to an existing agent,
241
244
  * which keeps its own instructions: between the start line and the steps,
@@ -15,6 +15,7 @@ import { templateScheduleStart } from '../core/system-agents/templates.js';
15
15
  import { planParameters, planWebhook, planWorkflowWithModel, workflowTemplate } from '../core/system-agents/workflow-planner.js';
16
16
  import { createTrigger, getTriggerStore, listTriggers, publicTrigger } from '../core/workflow-triggers.js';
17
17
  import { mcpAbilityNames } from '../core/mcp-ability-generator.js';
18
+ import { contextToolsFor } from '../core/mcp-apps.js';
18
19
  import { clearWorkflowFields, migrateWorkflowsFile, readWorkflow, readWorkflows, setWorkflowFields, validateParams, workflowRunMessage } from '../core/workflows.js';
19
20
  import { readEvals, workflowScores } from './workflow-evidence.js';
20
21
  import { isUnderWay, listRuns } from '../core/workflow-runs.js';
@@ -570,6 +571,13 @@ export async function createWorkflow(input, deps) {
570
571
  appsToConnect.push(app.title);
571
572
  continue;
572
573
  }
574
+ // A tool that has to be told which account, org or workspace to use
575
+ // comes with the app's read-only tool that lists them.
576
+ if (deps.appToolInputs && app.tools.length) {
577
+ const extra = await deps.appToolInputs(spec).then((tools) => contextToolsFor(app.tools, tools), () => []);
578
+ if (extra.length)
579
+ app.tools = [...app.tools, ...extra];
580
+ }
573
581
  const has = agent.apps?.find((a) => a.id === app.id);
574
582
  const toAdd = has ? app.tools.filter((remote) => !has.tools.includes(has.all?.find((t) => t.remote === remote)?.name ?? remote)) : app.tools;
575
583
  if (has && !toAdd.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.70",
3
+ "version": "0.3.71",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",