i-am-bee / bee-agent-framework

The framework for building scalable agentic applications.
https://i-am-bee.github.io/bee-agent-framework/
Apache License 2.0
91 stars 22 forks source link

BamChatLLM doesn't correctly deserialize if it was originally created via BAMChatLLM.fromPreset #78

Closed shmuelk closed 6 days ago

shmuelk commented 6 days ago

Describe the bug When the class BAMChatLLM serializes itself, the createSnapShot function simply does a shallowCopy of the config. This is problematic if the BAMChatLLM instance was created via BAMChatLLM.fromPreset, as the messagesToPrompt function is the loaded config references a local variable in the function in the class BAMChatLLMPreset.

I assume the same issue exists with the WatsonXChatLLM class.

To Reproduce Steps to reproduce the behavior:

  1. Use the following typescript file (it is the example examples/agent/bee_reusable.ts modified to work with BAM):
    
    import "dotenv/config.js";
    import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
    import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
    import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory";
    import { BAMChatLLM } from "bee-agent-framework/adapters/bam/chat";

const llm = BAMChatLLM.fromPreset("meta-llama/llama-3-8b-instruct");

// We create an agent let agent = new BeeAgent({ llm: llm, tools: [new DuckDuckGoSearchTool()], memory: new UnconstrainedMemory(), });

// We ask the agent let prompt = "Who is the president of USA?"; console.info(prompt); const response = await agent.run({ prompt, });
console.info(response.result.text);

// We can save (serialize) the agent const json = agent.serialize();

// We reinitialize the agent to the exact state he was agent = BeeAgent.fromSerialized(json);

// We continue in our conversation prompt = "When was he born?"; console.info(prompt); const response2 = await agent.run({ prompt, }); console.info(response2.result.text);



2. Set the GENAI_API_KEY environment variable to your BAM API key
3. Run: yarn start <above file>
4. See the error "template is not defined"

**Expected behavior**
The example should have worked normally.

**Set-up:**

- Bee version: [e.g. v0.0.27]
- Model provider [e.g. BAM]
Tomas2D commented 6 days ago

Thanks for the report. The issue has been fixed by https://github.com/i-am-bee/bee-agent-framework/commit/d7584ef11a38e3541c53265d2e51e4adacd83096.

The fix will be released in 0.0.28 (expect a release later today or tomorrow).

shmuelk commented 6 days ago

Thanks I just pulled from main and the problem is fixed.

Tomas2D commented 6 days ago

Great. Released in v0.0.28.