Skip to content

Commit 686ced8

Browse files
committed
hotfix for Component types
initial support for vault access through SDK
1 parent 660cf6d commit 686ced8

File tree

7 files changed

+133
-24
lines changed

7 files changed

+133
-24
lines changed

examples/01-agent-code-skill/01-prompting.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Agent, Scope } from '@smythos/sdk';
33
async function main() {
44
const agent = new Agent({
55
id: 'crypto-market-assistant',
6-
6+
77
name: 'CryptoMarket Assistant',
88
behavior: 'You are a crypto price tracker. You are given a coin id and you need to get the price of the coin in USD',
99
model: 'gpt-4o',
@@ -19,28 +19,6 @@ async function main() {
1919
return data.market_data;
2020
},
2121
});
22-
const imgSkill = agent.addSkill({
23-
name: 'ImageAnalyser',
24-
description: 'Any attachment should be processed by this function',
25-
process: async ({ image_url }) => {
26-
console.log(image_url);
27-
return 'Image analysed';
28-
},
29-
});
30-
// imgSkill.in({
31-
// image_url : {
32-
// type:'Binary',
33-
// description:'The image url that we will analyze'
34-
// }
35-
// })
36-
37-
38-
39-
const prompt = await agent.prompt('Analyze this image please ', {
40-
files: ['https://www.robuxio.com/wp-content/uploads/2023/05/Trend.png'],
41-
});
42-
console.log(prompt);
43-
4422

4523
//this will prompt the agent and use the agent's LLM to determine which skill to use
4624
const promptResult = await agent.prompt('What are the current prices of Bitcoin and Ethereum ?');
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Agent, Scope } from '@smythos/sdk';
2+
3+
async function main() {
4+
const agent = new Agent({
5+
id: 'image-analyser',
6+
7+
name: 'Image Analyser',
8+
behavior: 'You are a image analyser. You are given a image url and you need to analyse the image',
9+
model: 'gpt-4o',
10+
});
11+
12+
const imgSkill = agent.addSkill({
13+
name: 'ImageAnalyser',
14+
description: 'Any attachment should be processed by this function',
15+
process: async ({ image_url }) => {
16+
console.log(image_url);
17+
return 'Image analysed';
18+
},
19+
});
20+
imgSkill.in({
21+
image_url: {
22+
type: 'Binary',
23+
description: 'The image url that we will analyze',
24+
},
25+
});
26+
27+
const promptResult = await agent.prompt('Analyze this image please ', {
28+
files: ['https://www.robuxio.com/wp-content/uploads/2023/05/Trend.png'],
29+
});
30+
console.log(promptResult);
31+
}
32+
33+
main();

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@smythos/sdk",
3-
"version": "1.0.33",
3+
"version": "1.0.34",
44
"description": "SRE SDK",
55
"keywords": [
66
"smythos",

packages/sdk/src/Agent/Agent.class.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { LLMInstance, TLLMInstanceParams } from '../LLM/LLMInstance.class';
3333
import { AgentData, ChatOptions, Scope } from '../types/SDKTypes';
3434
import { MCP, MCPSettings, MCPTransport } from '../MCP/MCP.class';
3535
import { findClosestModelInfo } from '../LLM/Model';
36+
import { VaultInstance } from '../Vault/VaultInstance.class';
3637

3738
const console = SDKLog;
3839

@@ -577,6 +578,27 @@ export class Agent extends SDKObject {
577578
return this._vectorDBProviders;
578579
}
579580

581+
private _vault: VaultInstance;
582+
583+
/**
584+
* Access to the agent's team vault
585+
*
586+
* This will give you access to the current agent team vault, if no explicit team is set, the agent belongs to "default" team.
587+
*
588+
* @example
589+
* ```typescript
590+
* const value = await agent.vault.get('my-key');
591+
* ```
592+
*
593+
* @returns The vault instance
594+
*/
595+
public get vault() {
596+
if (!this._vault) {
597+
this._vault = new VaultInstance(AccessCandidate.agent(this._data.id));
598+
}
599+
return this._vault;
600+
}
601+
580602
/**
581603
* Add a skill to the agent, enabling it to perform specific tasks or operations.
582604
*

packages/sdk/src/Vault/Vault.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { AccessCandidate, ConnectorService } from '@smythos/sre';
2+
3+
export class Vault {
4+
/**
5+
* Get a value from the vault
6+
* @param key - The key to get the value for
7+
* @param candidate - The candidate to get the value for
8+
* @returns The value of the key
9+
*/
10+
static async get(key: string, candidate?: AccessCandidate) {
11+
if (!candidate) candidate = AccessCandidate.team('default');
12+
const vaultConnector = ConnectorService.getVaultConnector();
13+
const vaultRequester = vaultConnector.requester(candidate);
14+
15+
const value = await vaultRequester.get(key);
16+
return value;
17+
}
18+
19+
/**
20+
* List all keys in the vault
21+
* @param candidate - The candidate to list the keys for
22+
* @returns An array of keys
23+
*/
24+
static async listKeys(candidate?: AccessCandidate) {
25+
if (!candidate) candidate = AccessCandidate.team('default');
26+
27+
const vaultConnector = ConnectorService.getVaultConnector();
28+
const vaultRequester = vaultConnector.requester(candidate);
29+
30+
const keys = await vaultRequester.listKeys();
31+
return keys;
32+
}
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { AccessCandidate, ConnectorService, IAccessCandidate, IVaultRequest, VaultConnector } from '@smythos/sre';
2+
import { SRE } from '@smythos/sre';
3+
import { SDKObject } from '../Core/SDKObject.class';
4+
5+
export class VaultInstance extends SDKObject {
6+
#candidate: IAccessCandidate;
7+
#vaultRequester: IVaultRequest;
8+
constructor(candidate?: AccessCandidate) {
9+
super();
10+
this.#candidate = candidate || AccessCandidate.team('default');
11+
}
12+
13+
protected async init() {
14+
//if the SRE instance is not initializing, initialize it with default settings
15+
if (!SRE.initializing) SRE.init({});
16+
await SRE.ready();
17+
const vaultConnector = ConnectorService.getVaultConnector();
18+
this.#vaultRequester = vaultConnector.requester(this.#candidate);
19+
20+
this._readyPromise.resolve(true);
21+
}
22+
23+
/**
24+
* Get a value from the vault
25+
* @param key - The key to get the value for
26+
* @returns The value of the key
27+
*/
28+
public async get(key: string) {
29+
const value = await this.#vaultRequester.get(key);
30+
return value;
31+
}
32+
33+
/**
34+
* List all keys in the vault
35+
* @returns An array of keys
36+
*/
37+
public async listKeys() {
38+
const keys = await this.#vaultRequester.listKeys();
39+
return keys;
40+
}
41+
}

packages/sdk/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export * from './types/ExportedSRETypes';
2929
export * from './types/SDKTypes';
3030
export * from './utils/help';
3131
export * from './utils/index';
32+
export * from './Vault/Vault';
33+
export * from './Vault/VaultInstance.class';
3234
export * from './VectorDB/VectorDB.class';
3335
export * from './VectorDB/VectorDBInstance.class';
3436
export * from './Components/generated/APICall';

0 commit comments

Comments
 (0)