-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat: add agent blueprints — instance-scoped reusable agent config presets #4451
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
Open
chewieglass-labs
wants to merge
8
commits into
paperclipai:master
Choose a base branch
from
chewieglass-labs:feat/agent-blueprints
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d45ca50
feat: add agent blueprints — instance-scoped reusable agent config pr…
1ebc5b4
fix: register blueprint migrations in drizzle journal
5f3e4c8
fix: address greptile review — handleUse toast, lineage immutability,…
a264355
fix: use correct warn tone for ToastTone
7db7645
chore: trigger greptile re-review
d6dfbf7
fix: preserve instructionsContent on blueprint import
3fe4e9e
fix: preserve runtimeConfig and permissions on blueprint edit
465abd5
fix: blueprint edit/search/import polish
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| CREATE TABLE "agent_blueprints" ( | ||
| "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
| "name" text NOT NULL, | ||
| "description" text, | ||
| "role" text DEFAULT 'general' NOT NULL, | ||
| "title" text, | ||
| "icon" text, | ||
| "capabilities" text, | ||
| "tags" text[] DEFAULT '{}' NOT NULL, | ||
| "adapter_type" text DEFAULT 'process' NOT NULL, | ||
| "adapter_config" jsonb DEFAULT '{}' NOT NULL, | ||
| "runtime_config" jsonb DEFAULT '{}' NOT NULL, | ||
| "budget_monthly_cents" integer DEFAULT 0 NOT NULL, | ||
| "permissions" jsonb DEFAULT '{}' NOT NULL, | ||
| "instructions_content" text, | ||
| "metadata" jsonb, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| CREATE INDEX "agent_blueprints_role_idx" ON "agent_blueprints" USING btree ("role"); | ||
| --> statement-breakpoint | ||
| CREATE INDEX "agent_blueprints_name_idx" ON "agent_blueprints" USING btree ("name"); |
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,10 @@ | ||
| -- Add lineage tracking columns to agent_blueprints and agents | ||
|
|
||
| ALTER TABLE "agent_blueprints" | ||
| ADD COLUMN "source_agent_id" uuid, | ||
| ADD COLUMN "source_blueprint_id" uuid; | ||
|
|
||
| ALTER TABLE "agents" | ||
| ADD COLUMN "tags" text[] DEFAULT '{}' NOT NULL, | ||
| ADD COLUMN "source_blueprint_id" uuid | ||
| REFERENCES "agent_blueprints"("id") ON DELETE SET NULL; |
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,38 @@ | ||
| import { | ||
| pgTable, | ||
| uuid, | ||
| text, | ||
| integer, | ||
| timestamp, | ||
| jsonb, | ||
| index, | ||
| } from "drizzle-orm/pg-core"; | ||
|
|
||
| export const agentBlueprints = pgTable( | ||
| "agent_blueprints", | ||
| { | ||
| id: uuid("id").primaryKey().defaultRandom(), | ||
| name: text("name").notNull(), | ||
| description: text("description"), | ||
| role: text("role").notNull().default("general"), | ||
| title: text("title"), | ||
| icon: text("icon"), | ||
| capabilities: text("capabilities"), | ||
| tags: text("tags").array().notNull().default([]), | ||
| adapterType: text("adapter_type").notNull().default("process"), | ||
| adapterConfig: jsonb("adapter_config").$type<Record<string, unknown>>().notNull().default({}), | ||
| runtimeConfig: jsonb("runtime_config").$type<Record<string, unknown>>().notNull().default({}), | ||
| budgetMonthlyCents: integer("budget_monthly_cents").notNull().default(0), | ||
| permissions: jsonb("permissions").$type<Record<string, unknown>>().notNull().default({}), | ||
| instructionsContent: text("instructions_content"), | ||
| metadata: jsonb("metadata").$type<Record<string, unknown>>(), | ||
| sourceAgentId: uuid("source_agent_id"), | ||
| sourceBlueprintId: uuid("source_blueprint_id"), | ||
| createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), | ||
| updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(), | ||
| }, | ||
| (table) => ({ | ||
| roleIdx: index("agent_blueprints_role_idx").on(table.role), | ||
| nameIdx: index("agent_blueprints_name_idx").on(table.name), | ||
| }), | ||
| ); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { z } from "zod"; | ||
| import { AGENT_ROLES, AGENT_ICON_NAMES } from "../constants.js"; | ||
| import { agentAdapterTypeSchema } from "../adapter-type.js"; | ||
|
|
||
| export const createAgentBlueprintSchema = z.object({ | ||
| name: z.string().min(1), | ||
| description: z.string().optional().nullable(), | ||
| role: z.enum(AGENT_ROLES).optional().default("general"), | ||
| title: z.string().optional().nullable(), | ||
| icon: z.enum(AGENT_ICON_NAMES).optional().nullable(), | ||
| capabilities: z.string().optional().nullable(), | ||
| tags: z.array(z.string().min(1)).optional().default([]), | ||
| adapterType: agentAdapterTypeSchema, | ||
| adapterConfig: z.record(z.unknown()).optional().default({}), | ||
| runtimeConfig: z.record(z.unknown()).optional().default({}), | ||
| budgetMonthlyCents: z.number().int().nonnegative().optional().default(0), | ||
| permissions: z.record(z.unknown()).optional().default({}), | ||
| instructionsContent: z.string().optional().nullable(), | ||
| metadata: z.record(z.unknown()).optional().nullable(), | ||
| sourceAgentId: z.string().uuid().optional().nullable(), | ||
| sourceBlueprintId: z.string().uuid().optional().nullable(), | ||
| }); | ||
|
|
||
| export type CreateAgentBlueprint = z.infer<typeof createAgentBlueprintSchema>; | ||
|
|
||
| export const updateAgentBlueprintSchema = createAgentBlueprintSchema | ||
| .omit({ sourceAgentId: true, sourceBlueprintId: true }) | ||
| .partial(); | ||
|
|
||
| export type UpdateAgentBlueprint = z.infer<typeof updateAgentBlueprintSchema>; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { Router } from "express"; | ||
| import type { Db } from "@paperclipai/db"; | ||
| import { | ||
| createAgentBlueprintSchema, | ||
| updateAgentBlueprintSchema, | ||
| } from "@paperclipai/shared"; | ||
| import { validate } from "../middleware/validate.js"; | ||
| import { assertBoard, assertAuthenticated } from "./authz.js"; | ||
| import { notFound } from "../errors.js"; | ||
| import { agentBlueprintService } from "../services/agent-blueprints.js"; | ||
|
|
||
| export function agentBlueprintRoutes(db: Db) { | ||
| const router = Router(); | ||
| const svc = agentBlueprintService(db); | ||
|
|
||
| // Read endpoints are open to both board users and agents (agents need to | ||
| // query blueprints when the CEO is asked to hire from a template). | ||
| router.get("/blueprints", async (req, res) => { | ||
| assertAuthenticated(req); | ||
| const search = typeof req.query.search === "string" ? req.query.search : undefined; | ||
| const role = typeof req.query.role === "string" ? req.query.role : undefined; | ||
| res.json(await svc.list({ search, role })); | ||
| }); | ||
|
|
||
| router.get("/blueprints/:id", async (req, res) => { | ||
| assertAuthenticated(req); | ||
| const blueprint = await svc.get(req.params.id as string); | ||
| if (!blueprint) throw notFound("Blueprint not found"); | ||
| res.json(blueprint); | ||
| }); | ||
|
|
||
| router.post( | ||
| "/blueprints", | ||
| validate(createAgentBlueprintSchema), | ||
| async (req, res) => { | ||
| assertBoard(req); | ||
| const blueprint = await svc.create(req.body); | ||
| res.status(201).json(blueprint); | ||
| }, | ||
| ); | ||
|
|
||
| router.patch( | ||
| "/blueprints/:id", | ||
| validate(updateAgentBlueprintSchema), | ||
| async (req, res) => { | ||
| assertBoard(req); | ||
| const existing = await svc.get(req.params.id as string); | ||
| if (!existing) throw notFound("Blueprint not found"); | ||
| const updated = await svc.update(req.params.id as string, req.body); | ||
| res.json(updated); | ||
| }, | ||
| ); | ||
|
|
||
| router.delete("/blueprints/:id", async (req, res) => { | ||
| assertBoard(req); | ||
| const existing = await svc.get(req.params.id as string); | ||
| if (!existing) throw notFound("Blueprint not found"); | ||
| await svc.delete(req.params.id as string); | ||
| res.status(204).end(); | ||
| }); | ||
|
|
||
| return router; | ||
| } | ||
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,93 @@ | ||
| import type { Db } from "@paperclipai/db"; | ||
| import { agentBlueprints } from "@paperclipai/db"; | ||
| import { and, asc, eq, ilike, or } from "drizzle-orm"; | ||
| import type { CreateAgentBlueprint, UpdateAgentBlueprint } from "@paperclipai/shared"; | ||
|
|
||
| export function agentBlueprintService(db: Db) { | ||
| return { | ||
| async list(opts?: { search?: string; role?: string }) { | ||
| const conditions = []; | ||
| if (opts?.role) { | ||
| conditions.push(eq(agentBlueprints.role, opts.role)); | ||
| } | ||
| if (opts?.search) { | ||
| const q = `%${opts.search}%`; | ||
| conditions.push( | ||
| or( | ||
| ilike(agentBlueprints.name, q), | ||
| ilike(agentBlueprints.description, q), | ||
| ilike(agentBlueprints.capabilities, q), | ||
| ), | ||
| ); | ||
| } | ||
| return db | ||
| .select() | ||
| .from(agentBlueprints) | ||
| .where(conditions.length > 0 ? and(...conditions) : undefined) | ||
| .orderBy(asc(agentBlueprints.name)); | ||
| }, | ||
|
|
||
| async get(id: string) { | ||
| const [row] = await db | ||
| .select() | ||
| .from(agentBlueprints) | ||
| .where(eq(agentBlueprints.id, id)); | ||
| return row ?? null; | ||
| }, | ||
|
|
||
| async create(input: CreateAgentBlueprint) { | ||
| const [row] = await db | ||
| .insert(agentBlueprints) | ||
| .values({ | ||
| name: input.name, | ||
| description: input.description ?? null, | ||
| role: input.role ?? "general", | ||
| title: input.title ?? null, | ||
| icon: input.icon ?? null, | ||
| capabilities: input.capabilities ?? null, | ||
| tags: input.tags ?? [], | ||
| adapterType: input.adapterType, | ||
| adapterConfig: input.adapterConfig ?? {}, | ||
| runtimeConfig: input.runtimeConfig ?? {}, | ||
| budgetMonthlyCents: input.budgetMonthlyCents ?? 0, | ||
| permissions: input.permissions ?? {}, | ||
| instructionsContent: input.instructionsContent ?? null, | ||
| metadata: input.metadata ?? null, | ||
| sourceAgentId: input.sourceAgentId ?? null, | ||
| sourceBlueprintId: input.sourceBlueprintId ?? null, | ||
| }) | ||
| .returning(); | ||
| return row!; | ||
| }, | ||
|
|
||
| async update(id: string, input: UpdateAgentBlueprint) { | ||
| const patch: Partial<typeof agentBlueprints.$inferInsert> = {}; | ||
| if (input.name !== undefined) patch.name = input.name; | ||
| if (input.description !== undefined) patch.description = input.description ?? null; | ||
| if (input.role !== undefined) patch.role = input.role; | ||
| if (input.title !== undefined) patch.title = input.title ?? null; | ||
| if (input.icon !== undefined) patch.icon = input.icon ?? null; | ||
| if (input.capabilities !== undefined) patch.capabilities = input.capabilities ?? null; | ||
| if (input.tags !== undefined) patch.tags = input.tags; | ||
| if (input.adapterType !== undefined) patch.adapterType = input.adapterType; | ||
| if (input.adapterConfig !== undefined) patch.adapterConfig = input.adapterConfig; | ||
| if (input.runtimeConfig !== undefined) patch.runtimeConfig = input.runtimeConfig; | ||
| if (input.budgetMonthlyCents !== undefined) patch.budgetMonthlyCents = input.budgetMonthlyCents; | ||
| if (input.permissions !== undefined) patch.permissions = input.permissions; | ||
| if (input.instructionsContent !== undefined) patch.instructionsContent = input.instructionsContent ?? null; | ||
| if (input.metadata !== undefined) patch.metadata = input.metadata ?? null; | ||
| patch.updatedAt = new Date(); | ||
|
|
||
|
chewieglass-labs marked this conversation as resolved.
|
||
| const [row] = await db | ||
| .update(agentBlueprints) | ||
| .set(patch) | ||
| .where(eq(agentBlueprints.id, id)) | ||
| .returning(); | ||
| return row ?? null; | ||
| }, | ||
|
|
||
| async delete(id: string) { | ||
| await db.delete(agentBlueprints).where(eq(agentBlueprints.id, id)); | ||
| }, | ||
| }; | ||
| } | ||
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.