@@ -48,27 +48,55 @@ final class AgentBuilder
4848 /** @var array<MiddlewareInterface> */
4949 private array $ middleware = [];
5050
51+ /**
52+ * Set the LLM provider for the agent.
53+ *
54+ * @param ProviderInterface $provider The provider to use
55+ *
56+ * @return self For method chaining
57+ */
5158 public function provider (ProviderInterface $ provider ): self
5259 {
5360 $ this ->provider = $ provider ;
5461
5562 return $ this ;
5663 }
5764
65+ /**
66+ * Set the model identifier (e.g., 'gpt-4o', 'claude-sonnet-4-20250514').
67+ *
68+ * @param string $model The model name
69+ *
70+ * @return self For method chaining
71+ */
5872 public function model (string $ model ): self
5973 {
6074 $ this ->model = $ model ;
6175
6276 return $ this ;
6377 }
6478
79+ /**
80+ * Set the system instructions (system prompt) for the agent.
81+ *
82+ * @param string $instructions The system prompt text
83+ *
84+ * @return self For method chaining
85+ */
6586 public function instructions (string $ instructions ): self
6687 {
6788 $ this ->instructions = $ instructions ;
6889
6990 return $ this ;
7091 }
7192
93+ /**
94+ * Add a single tool to the agent.
95+ *
96+ * @param ToolInterface $tool The tool to register
97+ *
98+ * @return self For method chaining
99+ */
72100 public function tool (ToolInterface $ tool ): self
73101 {
74102 $ this ->tools [] = $ tool ;
@@ -77,7 +105,11 @@ public function tool(ToolInterface $tool): self
77105 }
78106
79107 /**
80- * @param array<ToolInterface> $tools
108+ * Add multiple tools to the agent at once.
109+ *
110+ * @param array<ToolInterface> $tools The tools to register
111+ *
112+ * @return self For method chaining
81113 */
82114 public function tools (array $ tools ): self
83115 {
@@ -86,34 +118,70 @@ public function tools(array $tools): self
86118 return $ this ;
87119 }
88120
121+ /**
122+ * Register an event hook (e.g., 'beforeToolCall', 'afterToolCall', 'onError').
123+ *
124+ * @param string $name The hook name
125+ * @param Closure $callback The callback to invoke when the hook fires
126+ *
127+ * @return self For method chaining
128+ */
89129 public function hook (string $ name , Closure $ callback ): self
90130 {
91131 $ this ->hooks [$ name ] = $ callback ;
92132
93133 return $ this ;
94134 }
95135
136+ /**
137+ * Set the maximum number of tokens the model can generate.
138+ *
139+ * @param int $maxTokens Maximum output tokens
140+ *
141+ * @return self For method chaining
142+ */
96143 public function maxTokens (int $ maxTokens ): self
97144 {
98145 $ this ->maxTokens = $ maxTokens ;
99146
100147 return $ this ;
101148 }
102149
150+ /**
151+ * Set the sampling temperature (higher = more creative, lower = more deterministic).
152+ *
153+ * @param float $temperature Temperature value (typically 0.0 to 1.0)
154+ *
155+ * @return self For method chaining
156+ */
103157 public function temperature (float $ temperature ): self
104158 {
105159 $ this ->temperature = $ temperature ;
106160
107161 return $ this ;
108162 }
109163
164+ /**
165+ * Set the maximum number of agentic turns (tool call loops) before stopping.
166+ *
167+ * @param int $maxTurns Maximum iterations of the agentic loop
168+ *
169+ * @return self For method chaining
170+ */
110171 public function maxTurns (int $ maxTurns ): self
111172 {
112173 $ this ->maxTurns = $ maxTurns ;
113174
114175 return $ this ;
115176 }
116177
178+ /**
179+ * Add a single middleware to the pipeline.
180+ *
181+ * @param MiddlewareInterface $middleware The middleware to add
182+ *
183+ * @return self For method chaining
184+ */
117185 public function addMiddleware (MiddlewareInterface $ middleware ): self
118186 {
119187 $ this ->middleware [] = $ middleware ;
@@ -122,7 +190,11 @@ public function addMiddleware(MiddlewareInterface $middleware): self
122190 }
123191
124192 /**
125- * @param array<MiddlewareInterface> $middleware
193+ * Add multiple middleware to the pipeline at once.
194+ *
195+ * @param array<MiddlewareInterface> $middleware The middleware to add
196+ *
197+ * @return self For method chaining
126198 */
127199 public function middleware (array $ middleware ): self
128200 {
@@ -131,6 +203,13 @@ public function middleware(array $middleware): self
131203 return $ this ;
132204 }
133205
206+ /**
207+ * Build and return the configured Agent instance.
208+ *
209+ * @return Agent The fully configured agent
210+ *
211+ * @throws InvalidArgumentException If provider or model is not set
212+ */
134213 public function create (): Agent
135214 {
136215 if ($ this ->provider === null ) {
0 commit comments