You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A have a simplistic Agent, basically the example examples/agents/first.ts, changed to work with BAM and wrapped with a Web Server, written using Express. At the end of every interaction the agent is serialized and set into the user's session. When requests come in, if the session has a serialized agent in it, it is restored, otherwise the agent is created from scratch.
This works for two iterations. On the third one it fails, with an exception:
undefined:3
return (...args)=>target.invoke(...args)
^
ReferenceError: target is not defined
To Reproduce
Add extra dependencies: yarn add express express-session @types/express @types/express-session
yarn start <code below>
In another terminal session:
a. curl -X POST --data-binary '{"text": "Who is the president of the USA"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
b. curl -X POST --data-binary '{"text": "How old is he?"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
c. curl -X POST --data-binary '{"text": "Where was he born?"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
Expected behavior
It should not fail.
Screenshots
Here is the terminal output of the server when it fails:
(node:52233) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[server]: Server is running at http://localhost:3000
Creating agent
Agent created
Running agent
Agent ran
Serializing agent
Agent serialized
Restoring agent from session
Agent restored from session
Running agent
Agent ran
Serializing agent
Agent serialized
Restoring agent from session
Agent restored from session
Running agent
undefined:3
return (...args)=>target.invoke(...args)
^
ReferenceError: target is not defined
at Object.eval [as callback] (eval at <anonymous> (file:///Users/kallner/Projects/ai-agents/bee-agent-framework/src/serializer/serializer.ts:1:11657), <anonymous>:3:26)
at run (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:203:40)
at _Emitter.invoke (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:204:60)
at Object.on.toBoundedFunction.value (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:106:29)
at run (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:203:40)
at _Emitter.invoke (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:204:60)
at Object.on.toBoundedFunction.value (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:106:29)
at run (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:203:40)
at _Emitter.invoke (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:204:60)
at _Emitter.emit (/Users/kallner/Projects/ai-agents/bee-agent-framework/src/emitter/emitter.ts:189:23)
Code snippets
Here is the code being run above:
import "dotenv/config.js";
import express, {Express, Request, Response } from 'express';
import session from 'express-session';
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { BAMChatLLM } from "bee-agent-framework/adapters/bam/chat";
import { TokenMemory } from "bee-agent-framework/memory/tokenMemory";
import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo";
const app: Express = express();
const port = process.env.PORT || 3000;
app.use(express.json());
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false
}));
declare module 'express-session' {
interface SessionData {
agent: string;
}
}
app.post("/", async (req: Request, res: Response) => {
var agent: BeeAgent;
if (req.session && req.session.agent) {
console.log("Restoring agent from session");
agent = BeeAgent.fromSerialized(req.session.agent);
console.log("Agent restored from session");
} else {
console.log("Creating agent");
const llm = BAMChatLLM.fromPreset("meta-llama/llama-3-8b-instruct");
agent = new BeeAgent({
llm, // for more explore 'bee-agent-framework/adapters'
memory: new TokenMemory({ llm }), // for more explore 'bee-agent-framework/memory'
tools: [new DuckDuckGoSearchTool(), new OpenMeteoTool()], // for more explore 'bee-agent-framework/tools'
});
console.log("Agent created");
}
console.log("Running agent");
const response = await agent.run(
{ prompt: req.body.text },
{
execution: {
maxRetriesPerStep: 3,
totalMaxRetries: 10,
maxIterations: 20,
},
}
);
console.log("Agent ran");
console.log("Serializing agent");
req.session.agent = agent.serialize();
console.log("Agent serialized");
res.send(response.result.text);
});
app.listen(port, () => {
console.log(`[server]: Server is running at http://localhost:${port}`);
});
Set-up:
Bee version: [e.g. v0.0.29]
Model provider [e.g. BAM]
The text was updated successfully, but these errors were encountered:
Describe the bug
A have a simplistic Agent, basically the example examples/agents/first.ts, changed to work with BAM and wrapped with a Web Server, written using Express. At the end of every interaction the agent is serialized and set into the user's session. When requests come in, if the session has a serialized agent in it, it is restored, otherwise the agent is created from scratch.
This works for two iterations. On the third one it fails, with an exception:
To Reproduce
yarn add express express-session @types/express @types/express-session
yarn start <code below>
a.
curl -X POST --data-binary '{"text": "Who is the president of the USA"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
b.
curl -X POST --data-binary '{"text": "How old is he?"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
c.
curl -X POST --data-binary '{"text": "Where was he born?"}' -H "Content-Type: application/json" --cookie cookiefile --cookie-jar cookiefile http://localhost:3000
Expected behavior
It should not fail.
Screenshots
Here is the terminal output of the server when it fails:
Code snippets
Here is the code being run above:
Set-up:
The text was updated successfully, but these errors were encountered: