mustafaskyer
10/15/2025, 4:38 PMtsx
import { Composio } from '@composio/core'
import { LangchainProvider } from '@composio/langchain'
import { createReactAgent } from '@langchain/langgraph/prebuilt'
import { ChatOpenAI } from '@langchain/openai'
const demoTools = ['GMAIL_FETCH_EMAILS']
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new LangchainProvider(),
})
async function testComposioFailedTools() {
const tools = await composio.tools.get('NotExistAccountId', {
tools: demoTools,
})
console.log(
'-- tools --',
tools.map((tool) => ({ name: tool.name, description: tool.description })),
)
const agent = createReactAgent({
tools,
llm: new ChatOpenAI({
model: 'gpt-4o-mini',
temperature: 0,
apiKey: process.env.OPENAI_API_KEY,
}),
})
const result = await agent.invoke({
messages: [
{ role: 'user', content: 'Hello, can you list my recent emails?' },
],
})
console.log('-- result --', result)
}
testComposioFailedTools()Akram Boussanni
10/15/2025, 6:11 PMmustafaskyer
10/15/2025, 6:22 PMAkram Boussanni
10/15/2025, 8:15 PMebro_880
10/15/2025, 9:05 PMcomposio.tools.get() in a try/catch and handle structured errors instead:
js
try {
const tools = await composio.tools.get('NotExistAccountId', { tools: ['GMAIL_FETCH_EMAILS'] })
if (!tools.length) throw new Error('No connected accounts')
} catch (err) {
if (err.code === 'NO_CONNECTED_ACCOUNTS' || err.status === 404) {
console.error('No connected Composio accounts. Prompt user to connect first.')
} else {
console.error('Unexpected error:', err)
}
}
You can also check with:
js
const accounts = await composio.accounts.list()
if (!accounts.length) console.warn('No connected accounts')
This is safer and won’t break if the message text changes.
I hope to helpmustafaskyer
10/15/2025, 11:49 PMtools.length will be > 1
also, since I am using Langchain, I've used the tryException tool pipe and seems working for now based on text message with a mapper for the text by an internal code
ts
export const composioErrorMapper: Record<string, string> = {
'No connected accounts found': 'NO_CONNECTED_ACCOUNTS_FOUND',
}Akram Boussanni
10/16/2025, 11:50 AMebro_880
10/16/2025, 11:53 AMtools.length to 0, so checking that alone isn’t sufficient.
using the LangChain tryException pipe and mapping known error messages to internal codes is a solid workaround for now. Ideally, Composio should expose structured error codes for each tool so mixed states can be handled cleanly.
until that’s available, your mapping layer is the right approach.