diff --git a/docs/agents.md b/docs/agents.md index 3cdebe6c..99c1e873 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -159,44 +159,45 @@ console.log(`Agent 🤖 : `, response.result.text); 1. **Error Handling** - ```typescript - protected async executeIteration(iteration: number): Promise { - try { - // ... iteration logic ... - } catch (error) { - this.devTools.emitter.emit('error', { error, context: { iteration } }); - throw error; - } - } - ``` +```typescript +function executeIteration(iteration: number): Promise { + try { + // ... iteration logic ... + } catch (error) { + this.devTools.emitter.emit("error", { error, context: { iteration } }); + throw error; + } +} +``` 2. **Memory Management** - ```typescript - protected async cleanup(): Promise { - await this.memory.store('lastCleanup', Date.now()); - // Clear temporary data - } - ``` +```typescript +function cleanup(): Promise { + await this.memory.store("lastCleanup", Date.now()); + // Clear temporary data +} +``` 3. **Event Emission** - ```typescript - protected emitProgress(progress: number): void { - this.devTools.emitter.emit('progress', { value: progress }); - } - ``` +```typescript +function emitProgress(progress: number): void { + this.devTools.emitter.emit("progress", { value: progress }); +} +``` 4. **Tool Management** - ```typescript - protected async validateTools(): Promise { - for (const tool of this.tools) { - if (!await tool.validate()) { - throw new Error(`Tool validation failed: ${tool.name}`); - } - } - } - ``` + +```typescript +function validateTools(): Promise { + for (const tool of this.tools) { + if (!(await tool.validate())) { + throw new Error(`Tool validation failed: ${tool.name}`); + } + } +} +``` ## Best Practices diff --git a/docs/cache.md b/docs/cache.md index a536e27a..980b62af 100644 --- a/docs/cache.md +++ b/docs/cache.md @@ -231,17 +231,15 @@ const jsonKey = JSONCacheKeyFn(input); ```typescript const customKeyFn: CacheKeyFn = (...args: any[]) => { - return args.map(arg => - typeof arg === 'object' - ? JSON.stringify(arg) - : String(arg) - ).join(':'); + return args.map((arg) => (typeof arg === "object" ? JSON.stringify(arg) : String(arg))).join(":"); }; -@Cache({ - cacheKey: customKeyFn -}) -method() { } +class CacheExample { + @Cache({ cacheKey: customKeyFn }) + method(seed: number) { + return seed; + } +} ``` ## Custom cache provider implementation @@ -312,11 +310,15 @@ _Source: [examples/cache/custom.ts](/examples/cache/custom.ts)_ ```typescript // Set appropriate TTL for data freshness - @Cache({ - ttl: 5 * 60 * 1000, // 5 minutes - enabled: true - }) - getData() { } + class DataManager { + @Cache({ + ttl: 5 * 60 * 1000, // 5 minutes + enabled: true, + }) + async fetchData() { + // Method implementation + } + } ``` 3. **Cache Invalidation** diff --git a/docs/errors.md b/docs/errors.md index 898afbfe..d1156163 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -258,23 +258,25 @@ try { 1. **Error Creation** - ```typescript - throw new FrameworkError("Clear, descriptive message", [originalError], { - context: { relevant: "data" }, - isFatal: whenUnrecoverable, - isRetryable: whenRetryPossible, - }); - ``` +```typescript +throw new FrameworkError("Clear, descriptive message", [originalError], { + context: { relevant: "data" }, + isFatal: whenUnrecoverable, + isRetryable: whenRetryPossible, +}); +``` 2. **Context Preservation** - ```typescript - catch (error) { - throw new FrameworkError("Higher-level context", [error], { - context: { ...error.context, newInfo: "value" } - }); - } - ``` +```typescript +try { + // Your code here +} catch (error) { + throw new FrameworkError("Higher-level context", [error], { + context: { ...error.context, newInfo: "value" }, + }); +} +``` 3. **Error Recovery** diff --git a/docs/serialization.md b/docs/serialization.md index fc27bb38..fd0f9b02 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -384,18 +384,7 @@ _Source: [examples/serialization/context.ts](/examples/serialization/context.ts) } ``` -3. **Circular Reference Management** - - ```typescript - // Always implement createEmpty and updateInstance - // for classes that might have circular references - createEmpty: () => new CustomType(), - updateInstance: (instance, update) => { - Object.assign(instance, update); - } - ``` - -4. **Performance Optimization** +3. **Performance Optimization** ```typescript // Cache serialization results when appropriate class SerializableCache { diff --git a/docs/tools.md b/docs/tools.md index e915f73d..5f920e54 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -269,20 +269,7 @@ _Source: [examples/tools/custom/python.ts](/examples/tools/custom/python.ts)_ ## Best Practices -1. **Input Validation** - - ```typescript - inputSchema() { - return z.object({ - query: z.string() - .min(1, "Query cannot be empty") - .max(1000, "Query too long") - .describe("Search query to execute") - }); - } - ``` - -2. **Error Handling** +1. **Error Handling** ```typescript try { @@ -296,7 +283,7 @@ _Source: [examples/tools/custom/python.ts](/examples/tools/custom/python.ts)_ } ``` -3. **Caching Strategy** +2. **Caching Strategy** ```typescript const tool = new SearchTool({ @@ -308,7 +295,7 @@ _Source: [examples/tools/custom/python.ts](/examples/tools/custom/python.ts)_ }); ``` -4. **Event Monitoring** +3. **Event Monitoring** ```typescript tool.emitter.on("start", ({ input }) => {