Prompt Agent
User Intent
Operation
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import { ModelServiceTypes, SpecificationTypes } from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// Define tools
const tools: ToolDefinitionInput[] = [
{
name: 'searchDocuments',
description: 'Search through ingested documents',
schema: JSON.stringify({
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' }
},
required: ['query']
})
}
];
// Implement tool handlers
const toolHandlers: Record<string, Function> = {
searchDocuments: async (args: { query: string }) => {
const results = await graphlit.queryContents({
search: args.query,
limit: 5
});
return {
count: results.contents.results.length,
results: results.contents.results.map(c => c.name)
};
}
};
// Prompt agent with tools
const result = await graphlit.promptAgent(
'Find information about API rate limiting', // prompt
undefined, // conversationId (optional - creates new)
undefined, // specification (optional - uses default)
tools, // tool definitions
toolHandlers // tool implementations
);
console.log(`AI Response: ${result.message}`);
console.log(`Tools called: ${result.toolCalls?.length || 0}`);
console.log(`Tokens used: ${result.usage?.totalTokens || 0}`);Parameters
promptAgent
Response
Developer Hints
promptAgent vs streamAgent
Feature
promptAgent
streamAgent
Tool Execution is Automatic
Checking Tool Calls
⚡ Performance Metrics
Variations
1. Simple Agent without Tools
2. Multi-Tool Agent
3. Multi-Turn Conversation with Tools
4. Agent with Custom Model
5. Error Handling for Tool Failures
6. Batch Processing with promptAgent
Common Issues
Production Example
Last updated