-
-
Notifications
You must be signed in to change notification settings - Fork 137
[Agent] Code grooming around tool call #1010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,16 +33,16 @@ public function addTool(string|object $class, string $name, string $description, | |
| } | ||
|
|
||
| /** | ||
| * @param class-string $reference | ||
| * @param class-string $className | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use only one name for a "thing". Line 30, this is called
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't have to be a class tho, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to understand. What could it be, if it's not a class, but the type is class-string? |
||
| */ | ||
| public function getTool(string $reference): iterable | ||
| public function getTool(string $className): iterable | ||
| { | ||
| if (!isset($this->tools[$reference])) { | ||
| throw ToolException::invalidReference($reference); | ||
| if (!isset($this->tools[$className])) { | ||
| throw ToolException::invalidReference($className); | ||
| } | ||
|
|
||
| foreach ($this->tools[$reference] as $tool) { | ||
| yield $this->convertAttribute($reference, $tool); | ||
| foreach ($this->tools[$className] as $tool) { | ||
| yield $this->convertAttribute($className, $tool); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ final class Toolbox implements ToolboxInterface | |
| * | ||
| * @var Tool[] | ||
| */ | ||
| private array $map; | ||
| private array $toolsMetadata; | ||
|
|
||
| /** | ||
| * @param iterable<object> $tools | ||
|
|
@@ -60,18 +60,18 @@ public function __construct( | |
|
|
||
| public function getTools(): array | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is something a bit hard to understand. I would like to rebame It will really ease on-boarding I guess. And it will fix inconsistency. For example : private function getMetadata(ToolCall $toolCall): Tool |
||
| { | ||
| if (isset($this->map)) { | ||
| return $this->map; | ||
| if (isset($this->toolsMetadata)) { | ||
| return $this->toolsMetadata; | ||
| } | ||
|
|
||
| $map = []; | ||
| $toolsMetadata = []; | ||
| foreach ($this->tools as $tool) { | ||
| foreach ($this->toolFactory->getTool($tool::class) as $metadata) { | ||
| $map[] = $metadata; | ||
| $toolsMetadata[] = $metadata; | ||
| } | ||
| } | ||
|
|
||
| return $this->map = $map; | ||
| return $this->toolsMetadata = $toolsMetadata; | ||
| } | ||
|
|
||
| public function execute(ToolCall $toolCall): ToolResult | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reduced the indirection. This reduce the depth in the stack.