import "dotenv/config";
import { Composio } from "@composio/core";
import { Agent, run, MemorySession } from "@openai/agents";
import { OpenAIAgentsProvider } from "@composio/openai-agents";
import { createInterface } from "readline/promises";
// Initialize Composio with OpenAI Agents provider
const composio = new Composio({ provider: new OpenAIAgentsProvider() });
// Create a session for your user
const userId = "user_123";
const session = await composio.create(userId);
const tools = await session.tools();
// For multi-turn, store the session ID in your db and reuse instead of calling create() again:
// const sessionId = session.sessionId;
// const session = await composio.use(sessionId);
const agent = new Agent({
name: "Personal Assistant",
instructions:
"Use Composio tools to complete the request. " +
"If a connection is required, share its Connect Link and wait. " +
"Ask for confirmation before creating, updating, or deleting data.",
model: "gpt-5.2",
tools,
});
const memory = new MemorySession();
const readline = createInterface({ input: process.stdin, output: process.stdout });
console.log(`
What task would you like me to help you with?
I can use tools like Gmail, GitHub, Linear, Notion, and more.
(Type 'exit' to exit)
Example tasks:
- 'Summarize my emails from today'
- 'List all open issues on the composio github repository'
`);
while (true) {
const input = (await readline.question("You: ")).trim();
if (input.toLowerCase() === "exit") break;
process.stdout.write("Assistant: ");
const result = await run(agent, input, { session: memory });
process.stdout.write(`${result.finalOutput}\n`);
}
readline.close();