-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥✨ 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
1 parent
3a38c36
commit 1add7c7
Showing
12 changed files
with
157 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. ' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.