-
Notifications
You must be signed in to change notification settings - Fork 14
feat(appkit): agents() plugin, createAgent(def), and markdown-driven agents #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+6,254
−32
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cf3a204
feat(appkit): agents() plugin, createAgent(def), and markdown-driven …
MarioCadenas 3107741
refactor(appkit): generalize default base system prompt
MarioCadenas 2ba1577
feat(appkit): optional serving_endpoint on agents plugin manifest
MarioCadenas 1c4f8d2
fix(appkit): agents manifest uses DATABRICKS_AGENT_ENDPOINT
MarioCadenas d74e3c0
feat(agents): folder-based markdown discovery (<id>/agent.md)
MarioCadenas fbc8500
refactor(appkit): promote MCP client + host policy to connectors/mcp
MarioCadenas 6505c67
refactor(appkit): extract normalizeToolResult, consumeAdapterStream, …
MarioCadenas 98aafda
fix(agents): propagate tool annotations through tool() → FunctionTool…
MarioCadenas cfbe28f
feat(agents): semantic ToolEffect — write/update/destructive tiers
MarioCadenas a20ab5e
chore(appkit): post-rebase formatting and lockfile sync
MarioCadenas 233b388
fix(appkit): apply review feedback to agents plugin
MarioCadenas e365bda
fix(appkit): forward sub-agent events into the parent SSE stream
MarioCadenas 4898f8c
fix(appkit): apply remaining review feedback (timeout config + result…
MarioCadenas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export { AppKitMcpClient } from "./client"; | ||
| export { | ||
| buildMcpHostPolicy, | ||
| type McpHostPolicyConfig, | ||
| } from "./host-policy"; | ||
| export type { McpEndpointConfig } from "./types"; |
4 changes: 2 additions & 2 deletions
4
...c/plugins/agents/tests/mcp-client.test.ts → ...t/src/connectors/mcp/tests/client.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * Input shape consumed by {@link AppKitMcpClient.connect}. Produced by the | ||
| * agents plugin from user-facing `HostedTool` declarations (see | ||
| * `plugins/agents/tools/hosted-tools.ts`) and accepted directly by the | ||
| * connector to keep its surface free of agent-layer concepts. | ||
| */ | ||
| export interface McpEndpointConfig { | ||
| /** Stable logical name used as the `mcp.<name>.*` tool prefix and in logs. */ | ||
| name: string; | ||
| /** Absolute URL (`https://…`) or workspace-relative path (`/api/2.0/mcp/…`). */ | ||
| url: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { AgentEvent } from "shared"; | ||
|
|
||
| interface ConsumeAdapterStreamOptions { | ||
| /** | ||
| * Optional abort signal. When aborted, the loop stops consuming (the caller | ||
| * is expected to have forwarded the same signal to `adapter.run` to stop | ||
| * upstream work). `undefined` is valid — standalone `runAgent` runs without | ||
| * a signal. | ||
| */ | ||
| signal?: AbortSignal; | ||
| /** | ||
| * Side-effect callback invoked once per adapter event, after the content | ||
| * accumulator has been updated. Use to fan events out to SSE translators, | ||
| * collect a raw event list for tests, or emit telemetry. | ||
| */ | ||
| onEvent?: (event: AgentEvent) => void; | ||
| } | ||
|
|
||
| /** | ||
| * Consume an adapter's event stream and aggregate the assistant's final text. | ||
| * | ||
| * Accumulation rule (shared across all agent-execution paths in AppKit): | ||
| * | ||
| * - `message_delta` events append their `content` to the running text. | ||
| * - A `message` event *replaces* the running text with its `content`. | ||
| * | ||
| * The two branches coexist because different adapters emit different shapes: | ||
| * streaming adapters (Databricks, Vercel AI) emit deltas chunk-by-chunk, | ||
| * while `LangChain`'s `on_chain_end` path emits a single final `message`. | ||
| * Without the replace branch, LangChain conversations silently dropped the | ||
| * assistant turn from thread history. | ||
| * | ||
| * Kept pure (no I/O, no mutable external state beyond the caller's `onEvent` | ||
| * side effect) so each execution path — HTTP streaming, sub-agents, and the | ||
| * standalone `runAgent` — can share one loop. | ||
| */ | ||
| export async function consumeAdapterStream( | ||
| stream: AsyncIterable<AgentEvent>, | ||
| opts: ConsumeAdapterStreamOptions = {}, | ||
| ): Promise<string> { | ||
| let text = ""; | ||
| for await (const event of stream) { | ||
| if (opts.signal?.aborted) break; | ||
| if (event.type === "message_delta") { | ||
| text += event.content; | ||
| } else if (event.type === "message") { | ||
| text = event.content; | ||
| } | ||
| opts.onEvent?.(event); | ||
| } | ||
| return text; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { ConfigurationError } from "../../errors"; | ||
| import type { AgentDefinition } from "./types"; | ||
|
|
||
| /** | ||
| * Pure factory for agent definitions. Returns the passed-in definition after | ||
| * cycle-detecting the sub-agent graph. Accepts the full `AgentDefinition` shape | ||
| * and is safe to call at module top-level. | ||
| * | ||
| * The returned value is a plain `AgentDefinition` — no adapter construction, | ||
| * no side effects. Register it with `agents({ agents: { name: def } })` or run | ||
| * it standalone via `runAgent(def, input)`. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * const support = createAgent({ | ||
| * instructions: "You help customers.", | ||
| * model: "databricks-claude-sonnet-4-5", | ||
| * tools: { | ||
| * get_weather: tool({ ... }), | ||
| * }, | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function createAgent(def: AgentDefinition): AgentDefinition { | ||
| detectCycles(def); | ||
| return def; | ||
| } | ||
|
|
||
| /** | ||
| * Walks the `agents: { ... }` sub-agent tree via DFS and throws if a cycle is | ||
| * found. Cycles would cause infinite recursion at tool-invocation time. | ||
| */ | ||
| function detectCycles(def: AgentDefinition): void { | ||
| const visiting = new Set<AgentDefinition>(); | ||
| const visited = new Set<AgentDefinition>(); | ||
|
|
||
| const walk = (current: AgentDefinition, path: string[]): void => { | ||
| if (visited.has(current)) return; | ||
| if (visiting.has(current)) { | ||
| throw new ConfigurationError( | ||
| `Agent sub-agent cycle detected: ${path.join(" -> ")}`, | ||
| ); | ||
| } | ||
| visiting.add(current); | ||
| for (const [childKey, child] of Object.entries(current.agents ?? {})) { | ||
| walk(child, [...path, childKey]); | ||
| } | ||
| visiting.delete(current); | ||
| visited.add(current); | ||
| }; | ||
|
|
||
| walk(def, [def.name ?? "(root)"]); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.