psadk
v1.1.35
Published
ps adk adapter
Readme
PSADK
ps adk adapter
- samples : sample agents using PSADK
Installation
$ npm install psadkDocumentation
The classes are documented here Documentation
Developing with PSADK
A2A Server
hello agent - simple chat agent
clone of https://github.com/a2aproject/a2a-samples/blob/main/samples/js/src/agents/coder/index.ts
import { getServiceToken, PSAgent, PSAgentLogger } from 'psadk';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
const token = await getServiceToken({});
const HelloAgent = new PSAgent({
name: 'HelloAgent',
description: 'A simple hello world agent',
instruction: 'You are a friendly assistant that greets users.',
token,
port: 41241,
log: new PSAgentLogger({ prefix: 'HelloAgent' }),
});
const { app } = HelloAgent.getA2AServer();
app.listen(41241, () => {
console.log('HelloAgent is running on http://localhost:41241');
});
}
main().catch((error) => {
console.error(error);
process.exit(1);
});create a .env file with the appropriate keys
PS_API_URL=https://dev.lionis.ai
PS_APP_KEY=sk_0abb4....
PS_CLIENT_ID=b5cc89b7-....
PS_PROJECT_ID=15a2e....
PS_WORKSPACE_ID=4ffba209-xxx-xxx-xxx-....
PS_SVC_CLIENT_ID=0483....
PS_SVC_CLIENT_SECRET=gfjt678...
PS_SVC_APP_KEY=sk_5f2967....
DEBUG=*
movie info agent - example with custom tools
clone of https://github.com/a2aproject/a2a-samples/blob/main/samples/js/src/agents/movie-agent/index.ts
import { PSAI, PSAgent, PSAgentLogger } from 'psadk';
import dotenv from 'dotenv';
import { movie_search_tool, movie_searchpeople_tool } from './tmdb_tools.js';
import { prompt } from './movie_agent_prompts.js';
dotenv.config();
async function main() {
// const token = await PSAI.getServiceToken({});
const token = (await PSAI.getAuthToken()).accessToken;
const instruction = prompt.replace('{{now}}', new Date().toLocaleString());
const MovieAgent = new PSAgent({
name: 'MovieAgent',
description: 'An agent that can answer questions about movies using TMDB.',
instruction,
model: 'gpt-4.1-mini',
token,
port: 41241,
log: new PSAgentLogger({ prefix: 'MovieAgent' }),
tools: [movie_search_tool, movie_searchpeople_tool],
});
const { app, port } = MovieAgent.getA2AServer();
app.listen(port, () => {
console.log(`MovieAgent is running on http://localhost:${port}`);
});
}
main().catch((error) => {
console.error(error);
process.exit(1);
});Use can use a2a inspector ui just enter the agent card url http://localhost:41241/.well-known/agent-card.json to interact with the agent
Custom tool
import { PSAgentTool } from 'psadk';
import { z } from 'zod/v4';
export const movie_search_tool = new PSAgentTool({
name: 'search_movies',
description: 'search TMDB for movies by title',
type: 'API',
local_execution: true,
hitl: true,
inputschema: {
title: `search_movies_inputs.`,
description: 'Inputs for search_movies tool.',
url: 'http://localhost/search_movies',
method: 'POST',
requestBody: z.toJSONSchema(
z
.object({
query: z.string().meta({
title: 'query',
description: 'The search query string for movies.',
}),
})
.meta({
title: 'search_movies_request_body',
description:
'The request body parameters for the search_movies tool.',
}),
{ io: 'input' },
),
},
runCallback: async ({ query }) => {
console.log('[tmdb:searchMovies]', JSON.stringify(query));
try {
const data = await callTmdbApi('movie', query);
// Only modify image paths to be full URLs
const results = data.results.map((movie: any) => {
if (movie.poster_path) {
movie.poster_path = `https://image.tmdb.org/t/p/w500${movie.poster_path}`;
}
if (movie.backdrop_path) {
movie.backdrop_path = `https://image.tmdb.org/t/p/w500${movie.backdrop_path}`;
}
return movie;
});
return {
status: 'success',
output: {
...data,
results,
},
};
} catch (error) {
console.error('Error searching movies:', error);
// Re-throwing allows the caller to handle it appropriately
throw error;
}
},
});Client: Sending a Message
The A2AClient makes it easy to communicate with any A2A-compliant agent.
// client.ts
import { A2AClient, SendMessageSuccessResponse } from '@a2a-js/sdk/client';
import { Message, MessageSendParams } from '@a2a-js/sdk';
import { v4 as uuidv4 } from 'uuid';
async function run() {
// Create a client pointing to the agent's Agent Card URL.
const client = await A2AClient.fromCardUrl(
'http://localhost:41241/.well-known/agent-card.json',
);
const sendParams: MessageSendParams = {
message: {
messageId: uuidv4(),
role: 'user',
parts: [{ kind: 'text', text: 'Hi there!' }],
kind: 'message',
},
};
const response = await client.sendMessage(sendParams);
if ('error' in response) {
console.error('Error:', response.error.message);
} else {
const result = (response as SendMessageSuccessResponse).result as Message;
console.log('Agent response:', result.parts[0].text); // "Hello, world!"
}
}
await run();