Skip to content

Commit 54e772c

Browse files
committed
chore(agent-core): update examples
1 parent 1514255 commit 54e772c

File tree

4 files changed

+105
-4
lines changed

4 files changed

+105
-4
lines changed

packages/agent-infra/agent/core/examples/mcp-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { MCPAgent } from '../src';
66
import { getModel } from './model';
77

8-
const model = getModel('gpt-4o-2024-11-20');
8+
const model = getModel('qwen3:1.7b');
99

1010
async function main() {
1111
const agent = new MCPAgent({

packages/agent-infra/agent/core/examples/model.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export type ModelName =
1414
| 'gpt-4o-2024-11-20'
1515
| 'aws_sdk_claude37_sonnet'
1616
| 'qwen2.5-coder-3b-instruct'
17-
| 'qwen2.5-7b-instruct-1m';
17+
| 'qwen2.5-7b-instruct-1m'
18+
| 'qwen3:1.7b';
1819

1920
export function getModel(name: ModelName) {
2021
if (
@@ -29,6 +30,15 @@ export function getModel(name: ModelName) {
2930
return new Model(openai, name);
3031
}
3132

33+
if (name === 'qwen3:1.7b') {
34+
const apiKey = 'openai';
35+
const openai = new OpenAI({
36+
baseURL: 'http://127.0.0.1:11434/v1',
37+
apiKey,
38+
});
39+
return new Model(openai, name);
40+
}
41+
3242
if (name === 'gpt-4o-2024-11-20') {
3343
const apiKey = 'openai';
3444
console.log(
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Code Review Report for PR #534
2+
3+
## Summary of Changes
4+
This pull request introduces significant improvements to error handling and formatting in the UI-TARS desktop application. The changes focus on:
5+
6+
1. Enhanced error classification and centralization.
7+
2. Refactored error handling logic in the `GUIAgent` class.
8+
3. Improved error display in the `ErrorMessage` component.
9+
4. Addition of new error status enums and the `GUIAgentError` class.
10+
11+
---
12+
13+
## Potential Issues and Bugs
14+
1. **Error Propagation in `guiAgentErrorParser`:**
15+
- The `guiAgentErrorParser` method attempts to classify and format errors but does not account for all potential error cases, such as unexpected types.
16+
- **Example:**
17+
```typescript
18+
+ if (!parseError && type === ErrorStatusEnum.ENVIRONMENT_ERROR) {
19+
+ parseError = new GUIAgentError(
20+
+ ErrorStatusEnum.ENVIRONMENT_ERROR,
21+
+ 'The environment error occurred when parsing the action',
22+
+ );
23+
+ }
24+
```
25+
Recommendation: Ensure all possible error types are handled and provide a fallback for unclassified errors.
26+
27+
2. **JSON Parsing in `ErrorMessage` Component:**
28+
- The `ErrorMessage` component attempts to parse a JSON string without validating its structure or handling syntax errors gracefully.
29+
- **Example:**
30+
```typescript
31+
+ const parsed = JSON.parse(text);
32+
+ if (parsed && typeof parsed === 'object' && 'status' in parsed) {
33+
+ parsedError = parsed as GUIAgentError;
34+
+ }
35+
```
36+
Recommendation: Wrap `JSON.parse` in a try-catch block and validate the parsed object more robustly.
37+
38+
3. **Testing Coverage:**
39+
- Code coverage reports indicate that new changes have reduced overall test coverage, particularly in `GUIAgent.ts` and `agent.ts`.
40+
**Codecov Report:**
41+
- `GUIAgent.ts`: 12.50% coverage with 33 missing lines.
42+
- `agent.ts`: 0% coverage with 10 missing lines.
43+
44+
---
45+
46+
## Code Quality Considerations
47+
1. **Error Class Design:**
48+
- Transition to the `GUIAgentError` class is a positive improvement, but consider making the `status` property non-optional to enforce stricter type safety.
49+
50+
2. **Consistency in Logging:**
51+
- Logging statements have been updated for better readability (e.g., `[GUIAgent]` prefixes). Ensure all logs adhere to this convention.
52+
- **Example:**
53+
```diff
54+
- logger.error('[runAgent error]', settings, error);
55+
+ logger.error('[onGUIAgentError]', settings, error);
56+
```
57+
58+
3. **Redundant Comments:**
59+
- Several comments mirror the code logic without adding value. For example:
60+
```typescript
61+
+ // Avoid guiAgentErrorParser itself in stack trace
62+
+ Error.captureStackTrace(parseError, this.guiAgentErrorParser);
63+
```
64+
Recommendation: Remove such comments to improve readability.
65+
66+
---
67+
68+
## Suggested Improvements
69+
1. **Enhance Validation:**
70+
- In `ErrorMessage`, validate the JSON structure more rigorously before casting it to `GUIAgentError`.
71+
72+
2. **Catch-All Error Handling:**
73+
- Add a generic catch-all clause in `guiAgentErrorParser` to ensure no errors slip through unhandled.
74+
75+
3. **Improve Test Coverage:**
76+
- Write unit tests to cover new logic in `GUIAgent.ts` and `ErrorMessage`. Focus on edge cases like malformed inputs and unhandled error types.
77+
78+
4. **Refactor Enums:**
79+
- The `ErrorStatusEnum` has been expanded. Consider grouping related enums into nested structures for better organization.
80+
81+
---
82+
83+
## Overall Assessment
84+
This pull request significantly enhances the error handling and debugging capabilities of the application. However, some areas require further attention, particularly robustness, test coverage, and code readability.
85+
86+
### Recommended Actions
87+
- Address the identified potential issues.
88+
- Write additional tests to improve code coverage.
89+
- Refactor code to simplify and standardize error handling further.
90+
91+
Once these changes are implemented, the PR will be ready for merging.

packages/agent-infra/agent/core/examples/weather.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { z } from 'zod';
1414
import { getModel } from './model';
1515

16-
const model = getModel('aws_sdk_claude37_sonnet');
16+
const model = getModel('qwen3:1.7b');
1717
// Create tool call provider explicitly
1818
const toolCallProvider = new OpenAIToolCallProvider();
1919

@@ -56,7 +56,7 @@ const agent = new Agent({
5656
2. "finish_reason" should always be "tool_calls"
5757
`,
5858
toolCallProvider, // Pass the provider explicitly
59-
maxIterations: 3,
59+
maxIterations: 10,
6060
});
6161

6262
async function main() {

0 commit comments

Comments
 (0)