@@ -43,15 +43,18 @@ class IntelligentAnalyzer implements SamplingAwareToolInterface
4343 public function execute(array $arguments): ToolResultInterface
4444 {
4545 // Let AI analyze and reason about complex data
46- $analysis = $this->sampling->createRequest([
47- 'role' => 'user',
48- 'content' => "Analyze this data and suggest optimizations: {$arguments['data']}"
49- ]);
50-
51- $aiResponse = $this->sampling->sendRequest($analysis);
46+ $analysis = $this->samplingClient->createTextRequest(
47+ "Analyze this data and suggest optimizations: {$arguments['data']}",
48+ new ModelPreferences(
49+ hints: [['name' => 'claude-3-sonnet']],
50+ intelligencePriority: 0.8
51+ ),
52+ null,
53+ 2000
54+ );
5255
5356 // Execute actions based on AI reasoning
54- return $this->processAIRecommendations($aiResponse );
57+ return TextToolResult($analysis );
5558 }
5659}
5760```
@@ -87,17 +90,21 @@ class CodeReviewAgent implements SamplingAwareToolInterface
8790 public function execute(array $arguments): ToolResultInterface
8891 {
8992 // AI analyzes code for patterns, security, and best practices
90- $review = $this->sampling->createRequest([
91- 'role' => 'user',
92- 'content' => "Review this code for security vulnerabilities,
93- performance issues, and suggest improvements:
94- {$arguments['code']}"
93+ $review = $this->samplingClient->createTextRequest(<<<Prompt
94+ Review this code for security vulnerabilities,
95+ performance issues, and suggest improvements:
96+ {$arguments[ ' code' ]}
97+ Prompt,
98+ new ModelPreferences(
99+ hints: [[ ' name' => 'claude-3-sonnet']],
100+ intelligencePriority: 0.8
101+ ),
102+ null,
103+ 2000
95104 ]);
96105
97- $aiAnalysis = $this->sampling->sendRequest($review);
98-
99106 // Generate actionable recommendations
100- return new TextResult ($this->formatReview($aiAnalysis ));
107+ return new TextToolResult ($this->formatReview($review ));
101108 }
102109}
103110```
@@ -108,28 +115,38 @@ class DataInsightAgent implements SamplingAwareToolInterface, StreamableToolInte
108115{
109116 public function execute(array $arguments): ToolResultInterface
110117 {
111- $this->notifier->notify("Analyzing dataset...", 0.1);
112-
113118 // Multi-step reasoning process
114119 $steps = [
115120 'Identify patterns and anomalies',
116121 'Generate statistical insights',
117122 'Create visualizations',
118123 'Recommend actions'
119124 ];
125+ $this->progressNotifier->sendProgress(
126+ progress: 0,
127+ total: count($steps)+1,
128+ message: "Analyzing dataset..."
129+ );
120130
121131 $insights = [];
122132 foreach ($steps as $i => $step) {
123- $request = $this->sampling->createRequest([
124- 'role' => 'user',
125- 'content' => "$step for this data: {$arguments['data']}"
126- ]);
127-
128- $insights[] = $this->sampling->sendRequest($request);
129- $this->notifier->notify("Completed: $step", ($i + 1) / count($steps));
133+ $insights[] = $this->samplingClient->createTextRequest(
134+ "$step for this data: {$arguments['data']}",
135+ new ModelPreferences(
136+ hints: [['name' => 'claude-3-sonnet']],
137+ intelligencePriority: 0.8
138+ ),
139+ null,
140+ 2000
141+ );
142+ $this->progressNotifier->sendProgress(
143+ progress: $i+1,
144+ total: count($steps)+1,
145+ message: $step
146+ );
130147 }
131148
132- return new TextResult ($this->compileReport($insights));
149+ return new TextToolResult ($this->compileReport($insights));
133150 }
134151}
135152```
@@ -144,20 +161,21 @@ class SupportAgent implements SamplingAwareToolInterface
144161 $context = $this->loadCustomerHistory($arguments['customer_id']);
145162
146163 // AI determines best response strategy
147- $strategy = $this->sampling->createRequest([
148- 'role' => 'system',
149- 'content' => 'You are an expert customer support agent.'
150- ], [
151- 'role' => 'user',
152- 'content' => "Customer issue: {$arguments['issue']}
153- History: $context
154- Determine the best resolution approach."
155- ]);
156-
157- $approach = $this->sampling->sendRequest($strategy);
164+ $strategy = $this->samplingClient->createTextRequest(<<<Prompt
165+ Customer issue: {$arguments[ ' issue' ]}
166+ History: $context
167+ Determine the best resolution approach.
168+ Prompt,
169+ new ModelPreferences(
170+ hints: [[ ' name' => 'claude-3-sonnet']],
171+ intelligencePriority: 0.8
172+ ),
173+ 'You are an expert customer support agent.',
174+ 2000
175+ );
158176
159- // Execute the recommended actions
160- return $this->executeResolution($approach, $arguments );
177+ // Send back the strategy for user approbation
178+ return new TextToolResult($strategy );
161179 }
162180}
163181```
0 commit comments