Skip to content

Commit

Permalink
fix(tools): resolve linting issues in HumanTool implementation
Browse files Browse the repository at this point in the history
Refactored \`human.ts\` to remove unused imports and variables:
- Removed unused \`ToolOutput\` import.
- Renamed \`options\` to \`_options\` to comply with linting rules for unused variables.

Refactored \`io.ts\` to eliminate console statements:
- Replaced \`console.error\` with comments for fallback handling.

These changes ensure that \`yarn lint\` runs without errors or warnings.

Ref: i-am-bee#121
  • Loading branch information
matiasmolinas committed Nov 29, 2024
1 parent 4542c02 commit 1387c66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
12 changes: 6 additions & 6 deletions examples/agents/experimental/humantool_agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv/config.js";
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { sharedConsoleReader } from "../../../src/helpers/io.js"; // Use the shared reader
import { sharedConsoleReader } from "bee-agent-framework/helpers/io";
import { FrameworkError } from "bee-agent-framework/errors";
import { TokenMemory } from "bee-agent-framework/memory/tokenMemory";
import { Logger } from "bee-agent-framework/logger/logger";
Expand All @@ -9,7 +9,7 @@ import { LocalPythonStorage } from "bee-agent-framework/tools/python/storage";
import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia";
import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo";
import { HumanTool } from "@/tools/human.js";
import { HumanTool } from "bee-agent-framework/tools/human";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat";
Expand All @@ -24,7 +24,7 @@ import {
BeeToolInputErrorPrompt,
BeeToolNoResultsPrompt,
BeeToolNotFoundPrompt,
} from "@/agents/bee/prompts.js";
} from "bee-agent-framework/agents/bee/prompts"; // Updated import path

// Set up logger
Logger.root.level = "silent"; // Disable internal logs
Expand Down Expand Up @@ -84,7 +84,7 @@ const reader = sharedConsoleReader();
if (codeInterpreterUrl) {
reader.write(
"🛠️ System",
`The code interpreter tool is enabled. Please ensure that it is running on ${codeInterpreterUrl}`,
`The code interpreter tool is enabled. Please ensure that it is running on ${codeInterpreterUrl}`
);
}

Expand All @@ -101,7 +101,7 @@ try {
totalMaxRetries: 10,
maxIterations: 20,
},
},
}
)
.observe((emitter) => {
// Show only final answers
Expand All @@ -128,7 +128,7 @@ try {
} else {
reader.write(
"Agent 🤖 : ",
"No result was returned. Ensure your input is valid or check tool configurations.",
"No result was returned. Ensure your input is valid or check tool configurations."
);
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/helpers/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createConsoleReader({
[role && R.piped(picocolors.red, picocolors.bold)(role), stripAnsi(data ?? "")]
.filter(Boolean)
.join(" ")
.concat("\n"),
.concat("\n")
);
},
async prompt(): Promise<string> {
Expand All @@ -50,9 +50,10 @@ export function createConsoleReader({
`${R.piped(picocolors.cyan, picocolors.bold)(input)}`
);
return stripAnsi(userInput.trim());
} catch (error) {
} catch (error: any) {
// Handle error during prompt
if (error.code === "ERR_USE_AFTER_CLOSE") {
console.error("Attempted to prompt after the reader was closed.");
// Provide a fallback or ignore, as this isn't critical for the core
}
return fallback ?? "";
}
Expand All @@ -70,7 +71,9 @@ export function createConsoleReader({

try {
rl.write(
`${picocolors.dim(`Interactive session has started. To escape, input 'q' and submit.\n`)}`
`${picocolors.dim(
`Interactive session has started. To escape, input 'q' and submit.\n`
)}`
);

for (let iteration = 1, userInput = ""; isActive; iteration++) {
Expand All @@ -95,15 +98,15 @@ export function createConsoleReader({

yield { prompt: userInput, iteration };
}
} catch (error) {
} catch (error: any) {
// Handle error during iteration gracefully
if (error.code === "ERR_USE_AFTER_CLOSE") {
console.error("Error: Attempted to use the reader after it was closed.");
// Fallback behavior or silent fail
}
} finally {
isActive = false;
rl.close(); // Ensure the reader is closed only once
}
},
};
}

}
6 changes: 3 additions & 3 deletions src/tools/human.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tool, ToolOutput, BaseToolRunOptions, StringToolOutput } from "@/tools/base.js";
import { Tool, BaseToolRunOptions, StringToolOutput } from "@/tools/base.js";
import { sharedConsoleReader } from "@/helpers/io.js"; // Shared reader
import { z } from "zod";

Expand All @@ -13,7 +13,7 @@ export class HumanTool extends Tool<StringToolOutput> {

async _run(
input: z.infer<ReturnType<typeof this.inputSchema>>,
options: BaseToolRunOptions
_options: BaseToolRunOptions
): Promise<StringToolOutput> {
const reader = sharedConsoleReader(); // Use shared reader instance

Expand All @@ -23,4 +23,4 @@ export class HumanTool extends Tool<StringToolOutput> {

return new StringToolOutput(userInput); // Return the user's input
}
}
}

0 comments on commit 1387c66

Please sign in to comment.