async function someTool(input: string, parentRunId: string): Promise<string> {
const subRunId = 'sub_run_id';
lunary.trackEvent('tool', 'start', {
runId: subRunId,
parentRunId,
input,
name: 'MyTool',
tags: ['tag1', 'tag2']
});
try {
const output = await someAsyncOperation(input);
lunary.trackEvent('tool', 'end', {
runId: subRunId,
parentRunId,
output,
});
return output;
} catch (error) {
lunary.trackEvent('tool', 'error', {
runId: subRunId,
parentRunId,
error: error.message, // Replace with actual error message
name: 'mySubAgentFunction'
});
}
}
// Use the main agent function
myAgentFunction('some input')
.then(output => console.log('Output:', output))
.catch(error => console.error('Error:', error));