Skip to content

Commit

Permalink
Shift to pnpm workspace packages; fix linting (#53)
Browse files Browse the repository at this point in the history
* Shift to pnpm workspace packages; fix linting

* Fix PR CI

* Add canary CI

* Remove forced test failure

* Ensure `@inngest/agent-kit` dep is built before we lint

* Ignore examples when publishing

* Create witty-mayflies-type.md

* Set all examples to `private`
  • Loading branch information
jpwilliams authored Jan 17, 2025
1 parent b0df157 commit 4d6b263
Show file tree
Hide file tree
Showing 48 changed files with 870 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [],
"ignore": ["demo", "quick-start", "swebench"],
"snapshot": {
"useCalculatedVersion": true,
"prereleaseTemplate": "{tag}-{datetime}-{commit}"
Expand Down
5 changes: 5 additions & 0 deletions .changeset/witty-mayflies-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/agent-kit": patch
---

Shift to pnpm workspace packages; fix linting
42 changes: 42 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Canary"

on:
pull_request:
branches:
- main
paths:
- ".changeset/**/*.md"

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
# Used to fetch all history so that changesets doesn't attempt to
# publish duplicate tags.
fetch-depth: 0
# Replaces `concurrency` - never cancels any jobs
- uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- run: pnpm install
- uses: "the-guild-org/[email protected]"
with:
tag: "alpha"
prepareScript: "pnpm run build"
env:
GITHUB_TOKEN: ${{ secrets.CHANGESET_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_ENV: test # disable npm access checks; they don't work in CI
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: pnpm run build
working-directory: packages/agent-kit
- run: pnpm run lint

test:
Expand Down
83 changes: 0 additions & 83 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
9 changes: 0 additions & 9 deletions demo/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions demo/.vscode/settings.json

This file was deleted.

20 changes: 0 additions & 20 deletions demo/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint";

export default tseslint.config(
{
ignores: ["dist", "eslint.config.mjs", "demo", "examples"],
ignores: ["**/dist", "eslint.config.mjs"],
},
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
Expand Down
2 changes: 1 addition & 1 deletion demo/index.ts → examples/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use(
serve({
client: inngest,
functions: [fn],
}),
})
);

app.listen(port, () => {
Expand Down
6 changes: 3 additions & 3 deletions demo/inngest.ts → examples/demo/inngest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
createAgent,
createNetwork,
createTool,
defaultRoutingAgent,
getDefaultRoutingAgent,
} from "@inngest/agent-kit";
import { EventSchemas, Inngest, openai } from "inngest";
import { z } from "zod";
Expand Down Expand Up @@ -139,6 +138,7 @@ Think carefully about the request that the user is asking for. Do not respond wi
});

const network = createNetwork({
name: "Code writing network",
agents: [codeWritingAgent.withModel(model), executingAgent.withModel(model)],
defaultModel: model,
maxIter: 4,
Expand All @@ -148,6 +148,6 @@ const network = createNetwork({
return executingAgent;
}

return defaultRoutingAgent.withModel(model);
return getDefaultRoutingAgent().withModel(model);
},
});
13 changes: 6 additions & 7 deletions demo/inngest_alt.ts → examples/demo/inngest_alt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { defaultRoutingAgent } from "@inngest/agent-kit";
import { getDefaultRoutingAgent } from "@inngest/agent-kit";
import { EventSchemas, Inngest } from "inngest";
import { z } from "zod";
import { codeWritingNetworkMiddleware } from "./mw";
Expand Down Expand Up @@ -36,18 +36,17 @@ export const fn = inngest.createFunction(
// This uses the defaut agentic router to determine which agent to handle first. You can
// optinoally specifiy the agent that should execute first, and provide your own logic for
// handling logic in between agent calls.
const result = await codeWritingNetwork.run(
event.data.input,
({ network }) => {
const result = await codeWritingNetwork.run(event.data.input, {
router: ({ network }) => {
if (network.state.kv.has("files")) {
// Okay, we have some files. Did an agent run tests?
return executingAgent;
}

return defaultRoutingAgent;
return getDefaultRoutingAgent();
},
);
});

return result;
},
}
);
19 changes: 9 additions & 10 deletions demo/mw.ts → examples/demo/mw.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { createAgent, createNetwork } from "@inngest/agent-kit";
import { InngestMiddleware, openai, type OpenAi } from "inngest";
import { createAgent, createNetwork, openai } from "@inngest/agent-kit";
import { InngestMiddleware, type OpenAi } from "inngest";

export const codeWritingNetworkMiddleware = (
defaultModelOptions: OpenAi.AiModelOptions,
defaultModelOptions: OpenAi.AiModelOptions
) => {
return new InngestMiddleware({
name: "Code Writing Agent Middleware",
init() {
const model = openai({ ...defaultModelOptions });
const codeWritingNetwork = createNetwork({
name: "Code writing network",
agents: [codeWritingAgent, executingAgent],
maxIter: 4,
defaultModel: openai({ ...defaultModelOptions }),
});

return {
onFunctionRun() {
return {
transformInput() {
const codeWritingNetwork = createNetwork({
agents: [codeWritingAgent, executingAgent],
maxIter: 4,
defaultModel: model,
});

return {
ctx: {
ai: {
Expand Down
20 changes: 20 additions & 0 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "demo",
"private": true,
"version": "1.0.0",
"main": "index.js",
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@inngest/agent-kit": "workspace:^",
"express": "^4.21.1",
"inngest": "^3.27.6-pr-776.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/express": "^5.0.0",
"typescript": "^5.6.3"
},
"packageManager": "[email protected]+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387"
}
File renamed without changes.
36 changes: 22 additions & 14 deletions examples/quick-start/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
import { createAgent, createNetwork, anthropic, createServer } from '@inngest/agent-kit';
import {
anthropic,
createAgent,
createNetwork,
createServer,
} from "@inngest/agent-kit";

const dbaAgent = createAgent({
name: 'Database administrator',
description: 'Provides expert support for managing PostgreSQL databases',
name: "Database administrator",
description: "Provides expert support for managing PostgreSQL databases",
system:
'You are a PostgreSQL expert database administrator. ' +
'You only provide answers to questions linked to Postgres database schema, indexes, extensions.',
"You are a PostgreSQL expert database administrator. " +
"You only provide answers to questions linked to Postgres database schema, indexes, extensions.",
model: anthropic({
model: 'claude-3-5-haiku-latest',
model: "claude-3-5-haiku-latest",
max_tokens: 1000,
}),
});

const securityAgent = createAgent({
name: 'Database Security Expert',
description: 'Provides expert guidance on PostgreSQL security, access control, audit logging, and compliance best practices',
system: 'You are a PostgreSQL security expert. ' +
'You only provide answers to questions linked to PostgreSQL security topics such as encryption, access control, audit logging, and compliance best practices.',
name: "Database Security Expert",
description:
"Provides expert guidance on PostgreSQL security, access control, audit logging, and compliance best practices",
system:
"You are a PostgreSQL security expert. " +
"You only provide answers to questions linked to PostgreSQL security topics such as encryption, access control, audit logging, and compliance best practices.",
model: anthropic({
model: 'claude-3-5-haiku-latest',
model: "claude-3-5-haiku-latest",
max_tokens: 1000,
}),
});

const devOpsNetwork = createNetwork({
name: 'DevOps team',
name: "DevOps team",
agents: [dbaAgent, securityAgent],
maxIter: 2,
defaultModel: anthropic({
model: 'claude-3-5-haiku-latest',
model: "claude-3-5-haiku-latest",
max_tokens: 1000,
}),
});

const server = createServer({
agents: [],
networks: [devOpsNetwork],
});

server.listen(3010, () => console.log('Agent kit running!'));
server.listen(3010, () => console.log("Agent kit running!"));
Loading

0 comments on commit 4d6b263

Please sign in to comment.