Slack summariser
With Composio’s managed authentication and tool calling, it’s easy to build the
AI agents that can interact with the real world while reducing the boilerplate
required to setup and manage the authentication. This cookbook will walk you through
the process of building agents using Composio
, LangChain
.
Prerequisites
- Python3.x
- UV
- Composio API key
- OpenAI API key
- Understanding of building AI agents (Preferably with LangChain)
Build slack agent
Let’s start by building an agent that can interact with your slack workspace using Composio.
Authenticating users
To authenticate your users with Composio you need an auth config for the given app, In this case you need one for slack. You can create and manage auth configs from the dashboard.
Composio platform provides composio managed authentication for some apps to help
you fast-track your development, slack
being one of them. You can use these
default auth configs for development, but for production you should always use
your own oauth app configuration.
Using dashboard is the preferred way of managing authentication configs, but if you want to do it manually you can follow the guide below
Click to expand
To create an authentication config for slack
you need client_id
and client_secret
from your Slack App. Once you have the required credentials
you can use the following piece of code to set up authentication for slack
.
This will create an authentication config for slack
which you can use to
authenticate your users for your app. Ideally you should just create one
authentication object per project, so check for an existing auth config
before you create a new one.
Once you have authentication management in place, we can start with connecting
your users to your slack
app. Let’s implement a function to connect the users
to your slack
app via composio.
Now, when creating tools for your agent always check if the user already has a connected account before creating a new one.
Modifiers
In the current setup, we are expanding too much unnecessary tokens because response
from SLACK_FETCH_CONVERSATION_HISTORY
tool call contains too much unnecessary
information. This can be fixed using after_execute
modifier. An after execute
modifier is called after a tool execution is complete, here you can process
and modify the response object to make it more easy to consume for your agent.
To register modifiers, include them in the composio.tools.get
call.
Putting everything together
So far, we have created an agent with ability to interact with your slack
workspace using the composio
SDK, functions to manage connected accounts
for users and a simple agent runner. Let’s package this as a CLI tool.
To test the above function as CLI, follow the steps below
-
Clone the repository
-
Setup environment
Fill the api keys
Create the virtual env
-
Run the agent
Using Composio for managed auth and tools
Composio reduces a lot of boilerplate for building AI agents with ability access and use a wide variety of apps. For example in this cookbook, to build slack
integration without composio you would have to write code to
- manage
slack
oauth app - manage user connections
- tools for your agents to interact with
slack
Using composio simplifies all of the above to a few lines of code as we’ve seen the cookbook.
Best practices
🔒 User Management:
- Use unique, consistent
user_id
values for each person - Each user maintains their own slack connection
- User IDs can be email addresses, usernames, or any unique identifier
Troubleshooting
Connection Issues:
- Ensure your
.env
file has validCOMPOSIO_API_KEY
andOPENAI_API_KEY
- Check that the user has completed
slack
authorization - Verify the user_id matches exactly between requests
API Errors:
- Check the server logs for detailed error messages
- Ensure request payloads match the expected format
- Visit
/docs
endpoint for API schema validation