Skip to content

Commit

Permalink
docs: updating DOCs, fixing Parsing errors
Browse files Browse the repository at this point in the history
Signed-off-by: Ismael Faro <[email protected]>
  • Loading branch information
ismaelfaro committed Dec 2, 2024
1 parent a934b19 commit 5561b8f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 86 deletions.
61 changes: 31 additions & 30 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,44 +159,45 @@ console.log(`Agent 🤖 : `, response.result.text);

1. **Error Handling**

```typescript
protected async executeIteration(iteration: number): Promise<IterationResult> {
try {
// ... iteration logic ...
} catch (error) {
this.devTools.emitter.emit('error', { error, context: { iteration } });
throw error;
}
}
```
```typescript
function executeIteration(iteration: number): Promise<IterationResult> {
try {
// ... iteration logic ...
} catch (error) {
this.devTools.emitter.emit("error", { error, context: { iteration } });
throw error;
}
}
```

2. **Memory Management**

```typescript
protected async cleanup(): Promise<void> {
await this.memory.store('lastCleanup', Date.now());
// Clear temporary data
}
```
```typescript
function cleanup(): Promise<void> {
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<void> {
for (const tool of this.tools) {
if (!await tool.validate()) {
throw new Error(`Tool validation failed: ${tool.name}`);
}
}
}
```

```typescript
function validateTools(): Promise<void> {
for (const tool of this.tools) {
if (!(await tool.validate())) {
throw new Error(`Tool validation failed: ${tool.name}`);
}
}
}
```

## Best Practices

Expand Down
30 changes: 16 additions & 14 deletions docs/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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**
Expand Down
30 changes: 16 additions & 14 deletions docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
13 changes: 1 addition & 12 deletions docs/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 3 additions & 16 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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({
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 5561b8f

Please sign in to comment.