Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
md 69 lines 2.09 KB
Rendered Raw
1 # Session-management Example
2
3 This example demonstrates how to use Composio SDK for session-management.
4
5 ## Setup
6
7 1. **Install dependencies:**
8 ```bash
9 pnpm install
10 ```
11
12 2. **Configure environment:**
13 ```bash
14 cp .env.example .env
15 ```
16
17 Then edit `.env` and add your API keys:
18 - `COMPOSIO_API_KEY`: Get it from [Composio Dashboard](https://app.composio.dev)
19
20 ## Running the Example
21
22 ```bash
23 # Run the example
24 pnpm start
25
26 # Run in development mode (with file watching)
27 pnpm dev
28 ```
29
30 ## What This Example Does
31
32 - Initializes Composio SDK
33 - Fetches available tools
34 - Demonstrates basic usage patterns
35
36 ## Verifying saved Session configs
37
38 `src/session-configs.ts` checks saved Session configs against a real project. It creates sessions, prints `PASS` or `FAIL` for each check, deletes the sessions it created, and exits non-zero on any failure. It never runs as part of `pnpm start`.
39
40 ```bash
41 COMPOSIO_API_KEY=... \
42 SESSION_CONFIG_ID=sc_... \
43 ARCHIVED_SESSION_CONFIG_ID=sc_... \
44 COMPOSIO_API_KEY_NO_FEATURE=... \
45 pnpm start:session-configs
46 ```
47
48 `COMPOSIO_API_KEY` must belong to a project with Session configs enabled, with one active and one archived config. `COMPOSIO_API_KEY_NO_FEATURE` is optional and belongs to a project without the feature, for the `403` check. The script also records whether `sessionPreset: SessionPreset.DIRECT_TOOLS` works with a saved config.
49
50 The checks follow every page of active and archived configs. Cleanup attempts every created Session and fails the run if any deletion fails. Run `pnpm test` to verify pagination and cleanup without an API key.
51
52 ## Customization
53
54 Edit `src/index.ts` to:
55 - Add specific apps you want to integrate with
56 - Implement your business logic
57 - Add error handling and logging
58
59 ## Related Examples
60
61 - [OpenAI Example](../openai) - Shows integration with OpenAI
62 - [LangChain Example](../langchain) - Shows integration with LangChain
63 - [More Examples](../) - Browse all available examples
64
65 ## Support
66
67 - [Documentation](https://docs.composio.dev)
68 - [Discord Community](https://discord.gg/composio)
69 - [GitHub Issues](https://github.com/ComposioHQ/composio/issues)