@smartledger/lumen-core
v1.0.3
Published
Core primitives for LumenChat multi-agent system
Maintainers
Readme
@lumenchat/core
Complete core primitives for LumenChat multi-agent system. Combines signatures and LLM capabilities into a unified package.
Features
- Agent Creation: Create complete agents with cryptographic identity and LLM capability
- Signatures: All cryptographic operations from @lumenchat/signatures
- LLM: All provider abstractions from @lumenchat/llm
- Unified API: Single import for all core functionality
Installation
npm install @lumenchat/coreThis automatically includes:
@lumenchat/signatures@lumenchat/llm
Quick Start
Create a Complete Agent
import { createAgent } from '@lumenchat/core';
const agent = await createAgent('MyAgent', {
type: 'openai',
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-4o-mini',
temperature: 0.3
});
// Get agent identity
const identity = agent.getIdentity();
// {
// name: 'MyAgent',
// publicKey: '02abc...',
// address: '1XYZ...',
// created: '2025-11-20T...'
// }
// Generate signed response
const schema = {
type: 'object',
properties: {
answer: { type: 'string' },
confidence: { type: 'number' }
},
required: ['answer', 'confidence']
};
const messages = [
{ role: 'user', content: 'What is 2+2?' }
];
const response = await agent.generate(messages, schema);
// {
// answer: 'The answer is 4',
// confidence: 1.0,
// _llm: { provider: 'openai', model: 'gpt-4o-mini', ... },
// _signature: { signature: '3044022...', publicKey: '02abc...', ... }
// }Use Individual Components
import {
createAgentKeys,
generateStructuredJSON,
signedStructuredResponse,
verifySignedEnvelope,
OpenAIProvider
} from '@lumenchat/core';
// Create keys
const keys = createAgentKeys('Agent-123');
// Create provider
const provider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY });
// Generate unsigned response
const unsignedResponse = await generateStructuredJSON(
messages,
schema,
{ temperature: 0.3 },
provider
);
// Generate signed response
const signedResponse = await signedStructuredResponse(
messages,
schema,
keys,
{ temperature: 0.3 },
provider
);
// Verify signature
const verification = verifySignedEnvelope(signedResponse);
console.log(verification.verified); // trueImport Namespaces
import { signatures, llm } from '@lumenchat/core';
// Use signatures
const keys = signatures.generateKeys();
const envelope = signatures.createSignedEnvelope(data, keys);
// Use LLM
const provider = new llm.OpenAIProvider();
const response = await llm.generateStructuredJSON(messages, schema, {}, provider);API Reference
createAgent(agentName, llmConfig)
Create a complete agent with keys and LLM capability.
Parameters:
agentName(string): Agent identifierllmConfig(Object): LLM configurationtype(string): Provider type ('openai')apiKey(string): API keymodel(string): Model nametemperature(number): Temperature
Returns: Promise<Object> - Agent instance with:
name(string): Agent namekeys(Object): Cryptographic keysprovider(BaseLLMProvider): LLM providerasync generate(messages, schema, options)- Generate signed responsegetIdentity()- Get agent identity info
Re-exported from @lumenchat/signatures
generateKeys()createAgentKeys(agentName, options)signData(data, privateKeyWIF)verifySignature(data, signatureHex, publicKey)createSignedEnvelope(data, agentKey, metadata)verifySignedEnvelope(envelope)initializePlatformKeys()getAddressFromPrivateKey(privateKeyWIF)getPublicKeyFromPrivateKey(privateKeyWIF)
Re-exported from @lumenchat/llm
BaseLLMProvider(class)OpenAIProvider(class)generateStructuredJSON(messages, schema, options, provider)signedStructuredResponse(messages, schema, agentKey, options, provider)createProvider(type, config)
Complete Example
import { createAgent, verifySignedEnvelope } from '@lumenchat/core';
// Create agent
const mathAgent = await createAgent('MathAgent', {
type: 'openai',
apiKey: process.env.OPENAI_API_KEY,
temperature: 0.2
});
// Define schema
const schema = {
type: 'object',
properties: {
calculation: { type: 'string' },
result: { type: 'number' },
steps: { type: 'array', items: { type: 'string' } }
},
required: ['calculation', 'result', 'steps'],
additionalProperties: false
};
// Generate response
const response = await mathAgent.generate(
[
{ role: 'system', content: 'You are a math expert.' },
{ role: 'user', content: 'Calculate (5 + 3) * 2' }
],
schema
);
console.log('Result:', response.result);
console.log('Steps:', response.steps);
// Verify signature
const verification = verifySignedEnvelope(response);
console.log('Verified:', verification.verified);
console.log('Agent:', verification.agentIdentity);Environment Variables
OPENAI_API_KEY: OpenAI API keyPLATFORM_PRIVATE_KEY: Platform private key (optional)
Documentation
License
PROPRIETARY - Copyright © 2025 Gregory J. Ward and SmartLedger.Technology
