Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
OPENAI_API_KEY="x"
OPENAI_MODEL="gpt-5.2"
LOG_LEVEL="info"
ARCADE_API_KEY="x"
USER_ID="<<your_name>>@gmail.com"
ARCADE_GATEWAY_URL="https://api.arcade.dev/mcp/your-gateway-slug"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.context
node_modules
.DS_Store
agent
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Bun installed on your computer - https://bun.com/docs/installation
- An OpenAI API Key - https://openai.com/
- An Arcade.dev API key - https://www.arcade.dev/
- An Arcade MCP Gateway URL - https://docs.arcade.dev/en/guides/mcp-gateways

## This Repo

Expand All @@ -24,7 +24,13 @@ cp .env.example .env
To run:

```bash
./agent.ts
./agent.ts chat
```

You can also override the gateway URL via CLI flag:

```bash
./agent.ts chat --gateway-url https://api.arcade.dev/mcp/your-gateway-slug
```

To Compile as a single-file executable
Expand Down
42 changes: 34 additions & 8 deletions agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Config } from "./classes/config";
import { Logger } from "./classes/logger";

import { setOpenAIClient } from "./utils/client";
import { createMcpServer } from "./utils/tools";

import { GeneralAgent } from "./agents/general";

Expand All @@ -15,13 +16,23 @@ setOpenAIClient(config);

program.version(pkg.version).name(pkg.name).description(pkg.description);

process.on("SIGINT", () => {
let mcpServer: ReturnType<typeof createMcpServer> | undefined;

async function cleanup() {
if (mcpServer) {
await mcpServer.close().catch(() => {});
}
}

process.on("SIGINT", async () => {
console.log("SIGINT: 👋 Bye!");
await cleanup();
process.exit(0);
});

process.on("SIGTERM", () => {
process.on("SIGTERM", async () => {
console.log("SIGTERM: 👋 Bye!");
await cleanup();
process.exit(0);
});

Expand All @@ -30,19 +41,34 @@ program
.description("Start an interactive chat session with the agent")
.argument("[message]", "The message to start the chat session with")
.option(
"-t, --toolkits <toolkits>",
"Comma-separated list of toolkits to use (e.g., gmail,slack)",
"gmail,slack",
"-g, --gateway-url <url>",
"Arcade MCP Gateway URL (overrides ARCADE_GATEWAY_URL env var)",
)
.action(async (message, options) => {
if (options.gatewayUrl) {
config.arcade_gateway_url = options.gatewayUrl;
}

if (!config.arcade_gateway_url) {
console.error(
"Error: Gateway URL is required. Set ARCADE_GATEWAY_URL env var or pass --gateway-url.",
);
process.exit(1);
}

mcpServer = createMcpServer(config);
await mcpServer.connect();

const agent = new GeneralAgent(config, logger);
const toolkitNames = options.toolkits.split(",").map((t) => t.trim());
await agent.interactiveChat(
async (input: string) => {
await agent.chat(input, toolkitNames);
await agent.chat(input, [mcpServer!]);
},
message,
toolkitNames,
async () => {
await cleanup();
process.exit(0);
},
);
});

Expand Down
9 changes: 5 additions & 4 deletions agents/general.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { WrappedAgent } from "../classes/wrappedAgent";
import type { Config } from "../classes/config";
import type { Logger } from "../classes/logger";
import type { MCPServerStreamableHttp } from "@openai/agents";
import chalk from "chalk";

export class GeneralAgent extends WrappedAgent {
constructor(config: Config, logger: Logger) {
const instructions = `
You are a general-purpose AI/LLM agent that can assist with a wide range of tasks.
You can take many actions via the toolkits provided to you.
ALWAYS prefer to call tools, but only when you are CERTAIN that you understand the user's request. Otherwise, ask clarifying questions. Do not rely on any pre-existing knowledge - only use the toolkits provided to you.
You can take many actions via the tools provided to you.
ALWAYS prefer to call tools, but only when you are CERTAIN that you understand the user's request. Otherwise, ask clarifying questions. Do not rely on any pre-existing knowledge - only use the tools provided to you.
Unless otherwise specified, you should respond in Markdown, and in Table format when you have multiple items to list.
You are in a terminal window, and the size of the terminal is ${Bun.env.COLUMNS}x${Bun.env.LINES}.
`;
super("GeneralAgent", instructions, config, logger);
}

async chat(prompt: string, toolkitNames: string[] = []) {
async chat(prompt: string, mcpServers: MCPServerStreamableHttp[] = []) {
this.logger.startSpan(chalk.gray(`Thinking...`));
const stream = await this.run(prompt, toolkitNames);
const stream = await this.run(prompt, mcpServers);
this.logger.endSpan();
return stream;
}
Expand Down
Loading