Skip to content

Commit 27103a4

Browse files
Merge pull request #56 from tripolskypetr/tool-action-helper
Tool action helper
2 parents 935b5af + f281a84 commit 27103a4

25 files changed

Lines changed: 1550 additions & 145 deletions
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: docs/api-reference/class/ActionSchemaService
3+
group: docs
4+
---
5+
6+
# ActionSchemaService
7+
8+
## Constructor
9+
10+
```ts
11+
constructor();
12+
```
13+
14+
## Properties
15+
16+
### loggerService
17+
18+
```ts
19+
loggerService: any
20+
```
21+
22+
### _actionToolNameSet
23+
24+
```ts
25+
_actionToolNameSet: any
26+
```
27+
28+
### register
29+
30+
```ts
31+
register: (toolName: string) => void
32+
```
33+
34+
Registers an action tool name in the internal Set.
35+
Logs the registration operation via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
36+
37+
### hasTool
38+
39+
```ts
40+
hasTool: (toolName: string) => boolean
41+
```
42+
43+
Checks if an action tool name exists in the internal Set.
44+
Logs the lookup operation via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.

docs/classes/ClientAgent.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ _resolveTools(): Promise<IAgentTool[]>;
120120
```
121121

122122
Resolves and combines tools from the agent's parameters and MCP tool list, ensuring no duplicate tool names.
123+
Ensures only one commit action tool is present in the list.
123124

124125
### _resolveSystemPrompt
125126

docs/classes/SchemaUtils.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ constructor();
1616

1717
## Properties
1818

19-
### __@PERSIST_WRITE_SYMBOL@4351
19+
### __@PERSIST_WRITE_SYMBOL@4419
2020

2121
```ts
22-
__@PERSIST_WRITE_SYMBOL@4351: any
22+
__@PERSIST_WRITE_SYMBOL@4419: any
2323
```
2424

2525
### writeSessionMemory

docs/functions/addCommitAction.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: docs/api-reference/function/addCommitAction
3+
group: docs
4+
---
5+
6+
# addCommitAction
7+
8+
```ts
9+
declare function addCommitAction<T = Record<string, any>>(params: ICommitActionToolParams<T>): string;
10+
```
11+
12+
Creates and registers a commit action tool for AI to execute actions (WRITE pattern).
13+
This implements the WRITE side of the command pattern - AI calls tool to modify system state.
14+
15+
**Flow:**
16+
1. AI calls tool with parameters
17+
2. validateParams runs (if provided) - validates parameters and returns error message or null
18+
3. If validation fails:
19+
- Error message is committed as tool output
20+
- failureMessage is executed (or error message if failureMessage not provided)
21+
- Flow stops
22+
4. If validation passes:
23+
- executeAction runs - performs the action
24+
- Action result is committed as tool output (or emptyContent if result is empty)
25+
- successMessage is executed
26+
27+
## Parameters
28+
29+
| Parameter | Description |
30+
|-----------|-------------|
31+
| `params` | Configuration object for the action tool |

docs/functions/addFetchInfo.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: docs/api-reference/function/addFetchInfo
3+
group: docs
4+
---
5+
6+
# addFetchInfo
7+
8+
```ts
9+
declare function addFetchInfo<T = Record<string, any>>(params: IFetchInfoToolParams<T>): string;
10+
```
11+
12+
Creates and registers a fetch info tool for AI to retrieve data (READ pattern).
13+
This implements the READ side of the command pattern - AI calls tool to get information without modifying state.
14+
15+
**Flow:**
16+
1. AI calls tool with parameters
17+
2. validateParams runs (if provided) - validates parameters structure. Returns true if valid, false if invalid
18+
3. If validation fails (returns false), tool execution is blocked
19+
4. If validation passes, fetchContent executes - retrieves data
20+
5. AI receives fetched content as tool output
21+
6. If content is empty, emptyContent handler is called
22+
23+
## Parameters
24+
25+
| Parameter | Description |
26+
|-----------|-------------|
27+
| `params` | Configuration object for the fetch tool |

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ group: docs
8585
- [PipelineValidationService](classes/PipelineValidationService.md)
8686
- [ExecutionValidationService](classes/ExecutionValidationService.md)
8787
- [NavigationSchemaService](classes/NavigationSchemaService.md)
88+
- [ActionSchemaService](classes/ActionSchemaService.md)
8889
- [OutlineSchemaService](classes/OutlineSchemaService.md)
8990
- [OutlineValidationService](classes/OutlineValidationService.md)
9091
- [RoundRobin](classes/RoundRobin.md)
@@ -107,6 +108,8 @@ group: docs
107108

108109
- [addAgentNavigation](functions/addAgentNavigation.md)
109110
- [addTriageNavigation](functions/addTriageNavigation.md)
111+
- [addCommitAction](functions/addCommitAction.md)
112+
- [addFetchInfo](functions/addFetchInfo.md)
110113
- [addAdvisor](functions/addAdvisor.md)
111114
- [addAgent](functions/addAgent.md)
112115
- [addCompletion](functions/addCompletion.md)
@@ -331,8 +334,12 @@ group: docs
331334
- [IConfig](interfaces/IConfig.md)
332335
- [INavigateToTriageParams](interfaces/INavigateToTriageParams.md)
333336
- [INavigateToAgentParams](interfaces/INavigateToAgentParams.md)
337+
- [ICommitActionParams](interfaces/ICommitActionParams.md)
338+
- [IFetchInfoParams](interfaces/IFetchInfoParams.md)
334339
- [IAgentNavigationParams](interfaces/IAgentNavigationParams.md)
335340
- [ITriageNavigationParams](interfaces/ITriageNavigationParams.md)
341+
- [ICommitActionToolParams](interfaces/ICommitActionToolParams.md)
342+
- [IFetchInfoToolParams](interfaces/IFetchInfoToolParams.md)
336343
- [IMakeDisposeParams](interfaces/IMakeDisposeParams.md)
337344
- [IMakeConnectionConfig](interfaces/IMakeConnectionConfig.md)
338345
- [ISessionConfig](interfaces/ISessionConfig.md)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: docs/api-reference/interface/ICommitActionParams
3+
group: docs
4+
---
5+
6+
# ICommitActionParams
7+
8+
Configuration parameters for creating a commit action handler (WRITE pattern).
9+
Defines validation, action execution, and response messages for state-modifying operations.
10+
11+
## Properties
12+
13+
### fallback
14+
15+
```ts
16+
fallback: (error: Error, clientId: string, agentName: string) => void
17+
```
18+
19+
Optional function to handle errors during action execution.
20+
Receives the error object, client ID, and agent name.
21+
22+
### validateParams
23+
24+
```ts
25+
validateParams: (dto: { clientId: string; agentName: string; toolCalls: IToolCall[]; params: T; }) => string | Promise<string>
26+
```
27+
28+
Optional function to validate action parameters.
29+
Returns error message string if validation fails, null if valid.
30+
31+
### executeAction
32+
33+
```ts
34+
executeAction: (params: T, clientId: string, agentName: string) => string | Promise<string>
35+
```
36+
37+
Function to execute the actual action (e.g., commitAppAction).
38+
Called only when parameters are valid and isLast is true.
39+
Returns result string to commit as tool output.
40+
41+
### emptyContent
42+
43+
```ts
44+
emptyContent: (params: T, clientId: string, agentName: string) => string | Promise<string>
45+
```
46+
47+
Optional function to handle when executeAction returns empty result.
48+
Returns message to commit as tool output.
49+
50+
### successMessage
51+
52+
```ts
53+
successMessage: string | ((params: T, clientId: string, agentName: string) => string | Promise<string>)
54+
```
55+
56+
Message to execute using executeForce after successful action execution.
57+
58+
### failureMessage
59+
60+
```ts
61+
failureMessage: string | ((params: T, clientId: string, agentName: string) => string | Promise<string>)
62+
```
63+
64+
Optional message to execute using executeForce when validation fails.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: docs/api-reference/interface/ICommitActionToolParams
3+
group: docs
4+
---
5+
6+
# ICommitActionToolParams
7+
8+
Parameters for configuring commit action tool (WRITE pattern).
9+
Creates a tool that executes actions and modifies system state.
10+
11+
## Properties
12+
13+
### toolName
14+
15+
```ts
16+
toolName: string
17+
```
18+
19+
The name of the tool to be created.
20+
21+
### function
22+
23+
```ts
24+
function: { name: string; description: string; parameters: { type: string; required: string[]; properties: { [key: string]: { type: string; description: string; enum?: string[]; }; }; }; } | ((clientId: string, agentName: string) => { ...; } | Promise<...>)
25+
```
26+
27+
Tool function schema (name, description, parameters).
28+
29+
### docNote
30+
31+
```ts
32+
docNote: string
33+
```
34+
35+
Optional documentation note for the tool.
36+
37+
### isAvailable
38+
39+
```ts
40+
isAvailable: (clientId: string, agentName: string, toolName: string) => boolean | Promise<boolean>
41+
```
42+
43+
Optional function to determine if the tool is available.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: docs/api-reference/interface/IFetchInfoParams
3+
group: docs
4+
---
5+
6+
# IFetchInfoParams
7+
8+
Configuration parameters for creating a fetch info handler (READ pattern).
9+
Defines the data fetching logic without modifying system state.
10+
11+
## Properties
12+
13+
### fallback
14+
15+
```ts
16+
fallback: (error: Error, clientId: string, agentName: string) => void
17+
```
18+
19+
Optional function to handle errors during fetch execution.
20+
Receives the error object, client ID, and agent name.
21+
22+
### fetchContent
23+
24+
```ts
25+
fetchContent: (params: T, clientId: string, agentName: string) => string | Promise<string>
26+
```
27+
28+
Function to fetch the content/data to be provided to the agent.
29+
This is the main data retrieval logic.
30+
31+
### emptyContent
32+
33+
```ts
34+
emptyContent: (content: string, clientId: string, agentName: string, toolName: string) => string | Promise<string>
35+
```
36+
37+
Optional function to handle when fetchContent returns empty result.
38+
Returns message to commit as tool output.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: docs/api-reference/interface/IFetchInfoToolParams
3+
group: docs
4+
---
5+
6+
# IFetchInfoToolParams
7+
8+
Parameters for configuring fetch info tool (READ pattern).
9+
Creates a tool that fetches and returns data to the AI without modifying system state.
10+
11+
## Properties
12+
13+
### toolName
14+
15+
```ts
16+
toolName: string
17+
```
18+
19+
The name of the tool to be created.
20+
21+
### function
22+
23+
```ts
24+
function: { name: string; description: string; parameters: { type: string; required: string[]; properties: { [key: string]: { type: string; description: string; enum?: string[]; }; }; }; } | ((clientId: string, agentName: string) => { ...; } | Promise<...>)
25+
```
26+
27+
Tool function schema (name, description, parameters).
28+
29+
### docNote
30+
31+
```ts
32+
docNote: string
33+
```
34+
35+
Optional documentation note for the tool.
36+
37+
### isAvailable
38+
39+
```ts
40+
isAvailable: (clientId: string, agentName: string, toolName: string) => boolean | Promise<boolean>
41+
```
42+
43+
Optional function to determine if the tool is available.
44+
45+
### validateParams
46+
47+
```ts
48+
validateParams: (dto: { clientId: string; agentName: string; toolCalls: IToolCall[]; params: T; }) => boolean | Promise<boolean>
49+
```
50+
51+
Optional validation function that runs before fetchContent. Returns boolean (true if valid, false if invalid).

0 commit comments

Comments
 (0)