Skip to content

Commit

Permalink
```
Browse files Browse the repository at this point in the history
🔥✨ feat(agents): remove deprecated agents and integrate WikiAgent with new LLM service

This commit removes the deprecated LlamaIndexAgent and its associated test files. It introduces the WikiAgent, which utilizes the new LLM service for processing tasks related to Wikipedia searches. The commit also includes updates to dependencies in `package.json` and adjustments to the conventional and GitMoji commit conventions, aiming for a clearer, more standardized commit message structure.

- Removed LlamaIndexAgent and associated test files.
- Introduced WikiAgent with integration to the new LLM service.
- Updated `package.json` dependencies, removing unused and adding new ones for better functionality.
- Adjusted various files to align with the new agent structure and improved coding standards.

This change enhances the plugin's capability to leverage language model services for processing Wikipedia search tasks, streamlining the workflow and improving efficiency.

🧹🚚 Chore: Clean up dependencies and codebase to improve maintainability and performance.
```
  • Loading branch information
awhiteside1 committed Sep 28, 2024
1 parent 3a38c36 commit 1add7c7
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 240 deletions.
2 changes: 1 addition & 1 deletion packages/agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"dotenv": "^16.4.5",
"effect": "^3.7.2",
"llamaindex": "0.6.9",
"mdast": "^3.0.0",
"mdast-util-heading-range": "^4.0.0",
"unist-util-find-all-between": "^2.1.0",
"ollama": "^0.5.9",
"pathe": "^1.1.2",
"radash": "^12.1.0",
Expand Down
11 changes: 4 additions & 7 deletions packages/agents/src/Agent/Agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ describe("Agent", () => {
const agent = new HelloAgent();
const program = Effect.gen(function* () {

const createTask = Effect.succeed(
new Task(

return yield* agent.process(new Task(
"Create a greeting for Alex Whiteside, a software architect who enjoys sarcasm and XKCD",
["Be Positive", "Be Creative"],
Schema.Struct({ greeting: Schema.String }),
),
);
return yield* agent.process(createTask);
Schema.Struct({ greeting: Schema.String }), ["Be Positive", "Be Creative"]
),);
});

const runnable = Effect.provide(program, AppLayer);
Expand Down
101 changes: 53 additions & 48 deletions packages/agents/src/Agent/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
import { Schema } from "@effect/schema";
import { LLMService } from "../services";
import { Effect } from "effect";
import { extractJSON, getMdast } from "../md";
import { getSectionByHeading } from "../md/getSection";
import { isRight } from "effect/Either";
import { Task, TaskResult } from "../task";
import { Prompts } from "./prompts";
import { InjectSection } from "./injectSection";
import { AIFunctionLike, AIFunctionSet } from "@agentic/core";
import {Schema} from "@effect/schema";
import {Effect} from "effect";
import {extractJSON, getMdast} from "../md";
import {getSectionByHeading} from "../md/getSection";
import {isRight} from "effect/Either";
import {type Task, TaskResult} from "../task";
import {Prompts} from "./prompts";
import {InjectSection} from "./injectSection";
import {generate} from "../ChatEngine/engine";
import type {ToolObject} from "../ChatEngine/tools";
import {Ollama} from "ollama";

export abstract class Agent {
abstract name: string;
abstract description: string;
public tools:AIFunctionLike[] = []
constructor() {}
abstract name: string
abstract description: string
public tools: ToolObject[] = []

generatePrompt(task: Task) {
const about = InjectSection(
"About You",
[
`You are a ${this.name}, responsible for ${this.description}.`,
"You are part of a multi-agent system which helps humans solve complex problems.",
].join("\n"),
);
generatePrompt(task: Task) {
const about = InjectSection(
'About You',
[
`You are a ${this.name}, responsible for ${this.description}.`,
'You are part of a multi-agent system which helps humans solve complex problems.',
].join('\n'),
)

const details = [
about,
Prompts.responseConventions,
InjectSection("Instructions", task.instructions),
InjectSection("Acceptance Criteria", task.acceptanceCriteria),
InjectSection("Schema (JsonSchema)", task.format),
];
const details = [
about,
Prompts.responseConventions,
InjectSection('Instructions', task.instructions),
InjectSection('Acceptance Criteria', task.acceptanceCriteria),
InjectSection('Schema (JsonSchema)', task.format),
]

return details.join("\n\n");
}
return details.join('\n\n')
}

process(task: Effect.Effect<Readonly<Task>, Error, never>) {
const generatePrompt = this.generatePrompt.bind(this);
return Effect.gen(function* () {
const llm = yield* LLMService;
process(task: Task) {
return Effect.gen(this, function* () {
const llm = new Ollama({host:'http://studio.local:11434'})
const prompt = this.generatePrompt(task)
const messages = [{ role: 'user', content: prompt }]
const response = yield* Effect.promise(()=>generate({
llm,
tools: this.tools,
model: 'mistral-small',
messageHistory: messages,
}))

const taskReal = yield* task;
const prompt = generatePrompt(taskReal);
const response = yield* llm.generateText(prompt, "mistral-small");
const lastMessage = response[-1]

const mdast = yield* getMdast(response);
const data = Schema.decodeEither(taskReal.format)(
extractJSON(getSectionByHeading(mdast, Prompts.sectionKeys.data)),
);
if (isRight(data)) {
return new TaskResult(data.right, "");
}
return new TaskResult(null, "null");
});
}
const mdast = getMdast(lastMessage.content)
const data = Schema.decodeEither(task.format)(
extractJSON(getSectionByHeading(mdast, Prompts.sectionKeys.data)),
)
if (isRight(data)) {
return new TaskResult(data.right, '')
}
return new TaskResult(null, 'null')
})
}
}
46 changes: 0 additions & 46 deletions packages/agents/src/Agent/LlamaIndexAgent.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/agents/src/Agent/injectSection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JSONSchema, Schema } from "@effect/schema";
import { JSONSchema, type Schema } from "@effect/schema";
import { Match } from "effect";
import { isArray } from "radash";
import { isSchema } from "@effect/schema/Schema";
Expand Down
18 changes: 0 additions & 18 deletions packages/agents/src/agents/Tools.spec.ts

This file was deleted.

58 changes: 0 additions & 58 deletions packages/agents/src/agents/WikiAgent.ts

This file was deleted.

29 changes: 20 additions & 9 deletions packages/agents/src/agents/WikiAgent/WikiAgent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { LlamaIndexAgent } from "./WikiAgent";
import { WikiAgent } from './WikiAgent'
import { Effect } from 'effect'
import { Task } from '../../task'
import { Schema } from '@effect/schema'
import { AppLayer } from '../../services'

describe("LLamaIndex", () => {
it("should whatever", {timeout:100000},async() => {
describe('LLamaIndex', () => {
it('should whatever', { timeout: 100000 }, async () => {
const agent = new WikiAgent()

const agent = new LlamaIndexAgent()
const program = Effect.gen(function* () {
const task = new Task(
'Get me background information about Cantaloupe, the fruit. ',
Schema.String,
)
return yield* agent.process(task)
})
const runnable = Effect.provide(program, AppLayer)
const result = await Effect.runPromise(runnable)

const result = await agent.process('Get me background information about Cantaloupe, the fruit. ')
expect(result).toBeDefined()
});

});
expect(result).toBeDefined()
})
})
22 changes: 6 additions & 16 deletions packages/agents/src/agents/WikiAgent/WikiAgent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { generate } from "../../ChatEngine/engine";
import { Ollama } from "ollama";
import { WikiSearchTool } from "./WikiTools";
import {WikiSearchTool} from './WikiTools'
import {Agent} from '../../Agent/Agent'

export class LlamaIndexAgent {

async process(message: string) {
const messages = [{ role: "user", content: message }];
const result = await generate({
llm: new Ollama({host:'http://studio.local:11434'}),
tools: [WikiSearchTool],
messageHistory: messages,
model: "llama3.1",
});

return result;
}
export class WikiAgent extends Agent {
tools = [WikiSearchTool]
name = 'Wikipedia Agent'
description = 'Searches wikipedia for information on requested topics. '
}
10 changes: 4 additions & 6 deletions packages/agents/src/md/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { remark } from "remark";
import remarkGfm from "remark-gfm";
import { Root } from "mdast";
import { Effect } from "effect";
import type { Root } from "mdast";


const markdownPipeline = remark().use(remarkGfm);

export const getMdast = (md: string) => {
return Effect.succeed(markdownPipeline.parse(md));
};
export const getMdast = (md: string) => markdownPipeline.parse(md)

export const stringifyMdast = (node: Root)=> Effect.succeed(markdownPipeline.stringify(node))
export const stringifyMdast = (node: Root)=> markdownPipeline.stringify(node)
2 changes: 1 addition & 1 deletion packages/agents/src/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Schema } from "@effect/schema";
export class Task {
constructor(
readonly instructions: string,
readonly acceptanceCriteria: Array<string> = [],
readonly format: Schema.Schema.AnyNoContext,
readonly acceptanceCriteria: Array<string> = [],
) {}
}

Expand Down
Loading

0 comments on commit 1add7c7

Please sign in to comment.