🔧 refactor: Optimize Agent Tool Loading and Fix Bedrock Tool Handling (#4641)

* fix: bedrock tool name regex

* fix: pass args as single input, attempt json first.

* refactor: remove toolMap from agent tool load as is not used

* fix: update formatAgentMessages test to use strictEqual for args comparison, testing new behavior
This commit is contained in:
Danny Avila 2024-11-05 11:24:26 -05:00 committed by GitHub
parent 3428c3c647
commit 0c2a583df8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 11 additions and 18 deletions

View file

@ -120,7 +120,7 @@ describe('formatAgentMessages', () => {
];
const result = formatAgentMessages(payload);
expect(result).toHaveLength(2);
expect(result[0].tool_calls[0].args).toBe('non-json-string');
expect(result[0].tool_calls[0].args).toStrictEqual({ input: 'non-json-string' });
});
it('should handle complex tool calls with multiple steps', () => {

View file

@ -189,10 +189,13 @@ const formatAgentMessages = (payload) => {
// TODO: investigate; args as dictionary may need to be provider-or-tool-specific
let args = _args;
try {
args = JSON.parse(args);
args = JSON.parse(_args);
} catch (e) {
// failed to parse, leave as is
if (typeof _args === 'string') {
args = { input: _args };
}
}
tool_call.args = args;
lastAIMessage.tool_calls.push(tool_call);