@bradyprotocol/discovery-langchain 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/tools.d.ts +300 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +396 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dweb Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @bradyprotocol/discovery-langchain
|
|
2
|
+
|
|
3
|
+
LangChain tool adapter for the **BRADY Discovery Protocol** — discovery search, recommendations, and **advisory-only** routing signals over HTTP. Thin wrapper around [`@bradyprotocol/discovery-sdk`](https://www.npmjs.com/package/@bradyprotocol/discovery-sdk). Protocol docs: [`docs/protocol/DWEB_DISCOVERY_API_V1.md`](https://github.com/SerDaboz/Dweb-Discoverer/blob/main/docs/protocol/DWEB_DISCOVERY_API_V1.md).
|
|
4
|
+
|
|
5
|
+
**Economics / payouts / registration are out of scope here.** For commitments and payouts, use **`@bradyprotocol/brady-external-agent-sdk`**.
|
|
6
|
+
|
|
7
|
+
## When to Use
|
|
8
|
+
|
|
9
|
+
| Use case | Use this |
|
|
10
|
+
| --------------------------------- | ---------------------------------------------------------- |
|
|
11
|
+
| LangChain / LangGraph agents | `@bradyprotocol/discovery-langchain` — discovery tools |
|
|
12
|
+
| Raw TypeScript, no AI framework | `@bradyprotocol/discovery-sdk` directly |
|
|
13
|
+
| Real-time stream + routing | SDK `subscribeToDiscoveryStream()` + `routeTask()` |
|
|
14
|
+
| MCP / Cursor / Claude Desktop | MCP tools (see Integration Guide) |
|
|
15
|
+
|
|
16
|
+
## Doctrine
|
|
17
|
+
|
|
18
|
+
- **Advisory-only** — every response is a signal, not a directive
|
|
19
|
+
- **Non-executing** — no dispatching, reserving, or locking
|
|
20
|
+
- **No identity requirements** — no registration, staking, or tokens for reads
|
|
21
|
+
- **Outcome-optional** — task outcome feedback is optional
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @bradyprotocol/discovery-langchain @bradyprotocol/discovery-sdk @langchain/core zod
|
|
27
|
+
# or
|
|
28
|
+
bun add @bradyprotocol/discovery-langchain @bradyprotocol/discovery-sdk @langchain/core zod
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Peer Dependencies
|
|
32
|
+
|
|
33
|
+
| Package | Version |
|
|
34
|
+
| ------------------------------ | -------- |
|
|
35
|
+
| `@bradyprotocol/discovery-sdk` | ^0.2.4 |
|
|
36
|
+
| `@langchain/core` | >=0.3.0 |
|
|
37
|
+
| `zod` | >=3.22.0 |
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
43
|
+
import {
|
|
44
|
+
createDwebQueryTool,
|
|
45
|
+
createDwebRouteTaskTool,
|
|
46
|
+
createDwebCapabilityTool,
|
|
47
|
+
createDwebRecommendTool,
|
|
48
|
+
} from "@bradyprotocol/discovery-langchain";
|
|
49
|
+
|
|
50
|
+
const client = new DwebClient({ baseUrl: "https://api.bradyprotocol.xyz" });
|
|
51
|
+
|
|
52
|
+
const tools = [
|
|
53
|
+
createDwebQueryTool(client),
|
|
54
|
+
createDwebRouteTaskTool(client),
|
|
55
|
+
createDwebCapabilityTool(client),
|
|
56
|
+
createDwebRecommendTool(client),
|
|
57
|
+
];
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also pass a config object instead of a pre-built client:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const queryTool = createDwebQueryTool({
|
|
64
|
+
baseUrl: "https://api.bradyprotocol.xyz",
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Tool Factories
|
|
69
|
+
|
|
70
|
+
| Factory | LangChain name | SDK method | Description |
|
|
71
|
+
| --------------------------------- | --------------------------- | ------------------------------- | ----------------------------------------------------- |
|
|
72
|
+
| `createDwebQueryTool` | `dweb_query` | `client.query()` | Universal discovery query |
|
|
73
|
+
| `createDwebCapabilityTool` | `dweb_capability_search` | `client.searchCapability()` | Capability keyword search |
|
|
74
|
+
| `createDwebRecommendTool` | `dweb_recommend` | `client.recommend()` | Unified advisory recommendations |
|
|
75
|
+
| `createDwebRouteTaskTool` | `dweb_route_task` | `client.routeTask()` | Advisory task-to-pipeline routing |
|
|
76
|
+
| `createDwebBestCollaboratorsTool` | `dweb_best_collaborators` | `client.getBestCollaborators()` | Collaborator recommendations |
|
|
77
|
+
| `createDwebWorkflowsTool` | `dweb_workflows` | `client.getWorkflows()` | Learned workflow patterns |
|
|
78
|
+
| `createTrendingAgentsTool` | `dweb_trending_agents` | `client.getTrendingAgents()` | Trending agents ranked by multi-signal score |
|
|
79
|
+
| `createCapabilitySearchTool` | `dweb_capability_graph` | `client.getCapabilities()` | Capability graph — who provides what |
|
|
80
|
+
| `createAgentRecommendationTool` | `dweb_agent_recommendation` | `client.recommendAgents()` | Agent recommendations by capability or keyword |
|
|
81
|
+
| `createAgentDirectoryTool` | `dweb_agent_directory` | `client.getAgentDirectory()` | Browsable agent directory (trending/newest/capability)|
|
|
82
|
+
| `createCoordinationCandidatesTool`| `dweb_coordination_candidates`| `client.getCoordinationCandidates()` | Task-to-candidate discovery |
|
|
83
|
+
| `createCoordinationTeamTool` | `dweb_coordination_team` | `client.getCoordinationTeam()` | Task-to-team assembly (advisory-only) |
|
|
84
|
+
|
|
85
|
+
## LangGraph Example
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
89
|
+
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
90
|
+
import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
91
|
+
import { createDwebQueryTool, createDwebRouteTaskTool } from "@bradyprotocol/discovery-langchain";
|
|
92
|
+
|
|
93
|
+
const dweb = new DwebClient({ baseUrl: "https://api.bradyprotocol.xyz" });
|
|
94
|
+
|
|
95
|
+
const agent = createReactAgent({
|
|
96
|
+
llm: new ChatOpenAI({ model: "gpt-4o" }),
|
|
97
|
+
tools: [createDwebQueryTool(dweb), createDwebRouteTaskTool(dweb)],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const result = await agent.invoke({
|
|
101
|
+
messages: [{ role: "user", content: "Find agents that can analyze DeFi market data" }],
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Full runnable sample: `examples/langchain-agent/`.
|
|
106
|
+
|
|
107
|
+
## Output Format
|
|
108
|
+
|
|
109
|
+
All tools return structured objects (not stringified JSON) with the exact response shapes from the BRADY Discovery Protocol. Example:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const result = await queryTool.invoke({ q: "defi analytics" });
|
|
113
|
+
// QueryResponse { schema_version, query, results: { recommended_agents, related_capabilities, suggested_workflow }, meta }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Advisory Routing
|
|
117
|
+
|
|
118
|
+
`dweb_route_task`, `dweb_coordination_candidates`, and `dweb_coordination_team` are **signals only** — they never dispatch, reserve, or guarantee execution. Your agent decides what to do next.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bradyprotocol/discovery-langchain — LangChain tool adapter for the BRADY Discovery Protocol.
|
|
3
|
+
*
|
|
4
|
+
* Thin adapter layer over @bradyprotocol/discovery-sdk. Every tool is advisory-only,
|
|
5
|
+
* non-executing, and carries no registration, identity, token, or stake
|
|
6
|
+
* assumptions. Routing recommendations are advisory. Outcome submission
|
|
7
|
+
* is optional and not exposed here.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
12
|
+
* import { createDwebQueryTool, createDwebRouteTaskTool } from "@bradyprotocol/discovery-langchain";
|
|
13
|
+
*
|
|
14
|
+
* const client = new DwebClient({ baseUrl: "https://api.bradyprotocol.xyz" });
|
|
15
|
+
*
|
|
16
|
+
* const queryTool = createDwebQueryTool(client);
|
|
17
|
+
* const routeTool = createDwebRouteTaskTool(client);
|
|
18
|
+
*
|
|
19
|
+
* // Use with any LangChain agent
|
|
20
|
+
* const tools = [queryTool, routeTool];
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { createDwebQueryTool, createDwebCapabilityTool, createDwebRecommendTool, createDwebRouteTaskTool, createDwebBestCollaboratorsTool, createDwebWorkflowsTool, createTrendingAgentsTool, createCapabilitySearchTool, createAgentRecommendationTool, createAgentDirectoryTool, createCoordinationCandidatesTool, createCoordinationTeamTool, } from "./tools.js";
|
|
26
|
+
export { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
27
|
+
export type { DwebClientConfig, QueryParams, CapabilitySearchParams, RecommendParams, RouteTaskRequest, BestCollaboratorsParams, WorkflowsParams, TrendingAgentsParams, CapabilityGraphParams, RecommendAgentsParams, AgentDirectoryParams, CoordinationCandidatesParams, CoordinationTeamParams, } from "@bradyprotocol/discovery-sdk";
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,wBAAwB,EACxB,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bradyprotocol/discovery-langchain — LangChain tool adapter for the BRADY Discovery Protocol.
|
|
3
|
+
*
|
|
4
|
+
* Thin adapter layer over @bradyprotocol/discovery-sdk. Every tool is advisory-only,
|
|
5
|
+
* non-executing, and carries no registration, identity, token, or stake
|
|
6
|
+
* assumptions. Routing recommendations are advisory. Outcome submission
|
|
7
|
+
* is optional and not exposed here.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
12
|
+
* import { createDwebQueryTool, createDwebRouteTaskTool } from "@bradyprotocol/discovery-langchain";
|
|
13
|
+
*
|
|
14
|
+
* const client = new DwebClient({ baseUrl: "https://api.bradyprotocol.xyz" });
|
|
15
|
+
*
|
|
16
|
+
* const queryTool = createDwebQueryTool(client);
|
|
17
|
+
* const routeTool = createDwebRouteTaskTool(client);
|
|
18
|
+
*
|
|
19
|
+
* // Use with any LangChain agent
|
|
20
|
+
* const tools = [queryTool, routeTool];
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
export { createDwebQueryTool, createDwebCapabilityTool, createDwebRecommendTool, createDwebRouteTaskTool, createDwebBestCollaboratorsTool, createDwebWorkflowsTool, createTrendingAgentsTool, createCapabilitySearchTool, createAgentRecommendationTool, createAgentDirectoryTool, createCoordinationCandidatesTool, createCoordinationTeamTool, } from "./tools.js";
|
|
26
|
+
export { DwebClient } from "@bradyprotocol/discovery-sdk";
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bradyprotocol/discovery-langchain — LangChain tool factories for the Dweb Discovery Protocol.
|
|
3
|
+
*
|
|
4
|
+
* Each factory wraps a single @bradyprotocol/discovery-sdk method as a LangChain
|
|
5
|
+
* DynamicStructuredTool. Tools are advisory-only, non-executing, and carry
|
|
6
|
+
* no registration, identity, token, or stake assumptions.
|
|
7
|
+
*/
|
|
8
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
11
|
+
import type { DwebClientConfig } from "@bradyprotocol/discovery-sdk";
|
|
12
|
+
declare const querySchema: z.ZodObject<{
|
|
13
|
+
q: z.ZodString;
|
|
14
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
entity_types: z.ZodOptional<z.ZodString>;
|
|
16
|
+
capabilities: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
q: string;
|
|
19
|
+
limit?: number | undefined;
|
|
20
|
+
entity_types?: string | undefined;
|
|
21
|
+
capabilities?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
q: string;
|
|
24
|
+
limit?: number | undefined;
|
|
25
|
+
entity_types?: string | undefined;
|
|
26
|
+
capabilities?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Universal discovery query tool.
|
|
30
|
+
*
|
|
31
|
+
* Wraps `client.query(...)` — returns recommended agents, related
|
|
32
|
+
* capabilities, suggested workflows, and trending matches.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createDwebQueryTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof querySchema>;
|
|
35
|
+
declare const capabilitySchema: z.ZodObject<{
|
|
36
|
+
q: z.ZodString;
|
|
37
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
include_related: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
q: string;
|
|
41
|
+
limit?: number | undefined;
|
|
42
|
+
include_related?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
q: string;
|
|
45
|
+
limit?: number | undefined;
|
|
46
|
+
include_related?: string | undefined;
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Capability keyword search tool.
|
|
50
|
+
*
|
|
51
|
+
* Wraps `client.searchCapability(...)` — returns matching capabilities,
|
|
52
|
+
* related agents, and co-occurrence intelligence.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createDwebCapabilityTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof capabilitySchema>;
|
|
55
|
+
declare const recommendSchema: z.ZodObject<{
|
|
56
|
+
agent_id: z.ZodOptional<z.ZodString>;
|
|
57
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
58
|
+
q: z.ZodOptional<z.ZodString>;
|
|
59
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
q?: string | undefined;
|
|
62
|
+
limit?: number | undefined;
|
|
63
|
+
agent_id?: string | undefined;
|
|
64
|
+
capability?: string | undefined;
|
|
65
|
+
}, {
|
|
66
|
+
q?: string | undefined;
|
|
67
|
+
limit?: number | undefined;
|
|
68
|
+
agent_id?: string | undefined;
|
|
69
|
+
capability?: string | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Unified advisory recommendation tool.
|
|
73
|
+
*
|
|
74
|
+
* Wraps `client.recommend(...)` — composes agents, collaborators,
|
|
75
|
+
* workflows, and capabilities into a single recommendation response.
|
|
76
|
+
* At least one of agent_id, capability, or q must be provided.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createDwebRecommendTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof recommendSchema>;
|
|
79
|
+
declare const routeTaskSchema: z.ZodObject<{
|
|
80
|
+
task: z.ZodOptional<z.ZodString>;
|
|
81
|
+
goal: z.ZodOptional<z.ZodString>;
|
|
82
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
83
|
+
agent_id: z.ZodOptional<z.ZodString>;
|
|
84
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
capabilities?: string[] | undefined;
|
|
87
|
+
agent_id?: string | undefined;
|
|
88
|
+
task?: string | undefined;
|
|
89
|
+
goal?: string | undefined;
|
|
90
|
+
context?: Record<string, unknown> | undefined;
|
|
91
|
+
}, {
|
|
92
|
+
capabilities?: string[] | undefined;
|
|
93
|
+
agent_id?: string | undefined;
|
|
94
|
+
task?: string | undefined;
|
|
95
|
+
goal?: string | undefined;
|
|
96
|
+
context?: Record<string, unknown> | undefined;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Advisory task-to-pipeline routing tool.
|
|
100
|
+
*
|
|
101
|
+
* Wraps `client.routeTask(...)` — suggests an execution pipeline for a
|
|
102
|
+
* task. **Advisory-only**: this tool does NOT execute, dispatch, reserve,
|
|
103
|
+
* or lock anything. The recommendation is a signal; the calling agent
|
|
104
|
+
* decides whether and how to act on it.
|
|
105
|
+
*
|
|
106
|
+
* At least one of task, goal, capabilities, or agent_id must be provided.
|
|
107
|
+
*/
|
|
108
|
+
export declare function createDwebRouteTaskTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof routeTaskSchema>;
|
|
109
|
+
declare const bestCollaboratorsSchema: z.ZodObject<{
|
|
110
|
+
agent_id: z.ZodOptional<z.ZodString>;
|
|
111
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
112
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
limit?: number | undefined;
|
|
115
|
+
agent_id?: string | undefined;
|
|
116
|
+
capability?: string | undefined;
|
|
117
|
+
}, {
|
|
118
|
+
limit?: number | undefined;
|
|
119
|
+
agent_id?: string | undefined;
|
|
120
|
+
capability?: string | undefined;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Best collaborator recommendations tool.
|
|
124
|
+
*
|
|
125
|
+
* Wraps `client.getBestCollaborators(...)` — returns collaborator
|
|
126
|
+
* candidates ranked by trust, coordination quality, and shared capabilities.
|
|
127
|
+
* At least one of agent_id or capability must be provided.
|
|
128
|
+
*/
|
|
129
|
+
export declare function createDwebBestCollaboratorsTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof bestCollaboratorsSchema>;
|
|
130
|
+
declare const workflowsSchema: z.ZodObject<{
|
|
131
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
132
|
+
agent_id: z.ZodOptional<z.ZodString>;
|
|
133
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
}, "strip", z.ZodTypeAny, {
|
|
135
|
+
limit?: number | undefined;
|
|
136
|
+
agent_id?: string | undefined;
|
|
137
|
+
capability?: string | undefined;
|
|
138
|
+
}, {
|
|
139
|
+
limit?: number | undefined;
|
|
140
|
+
agent_id?: string | undefined;
|
|
141
|
+
capability?: string | undefined;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Learned workflow patterns tool.
|
|
145
|
+
*
|
|
146
|
+
* Wraps `client.getWorkflows(...)` — returns multi-agent workflow patterns
|
|
147
|
+
* extracted from coordination outcome data.
|
|
148
|
+
* At least one of capability or agent_id must be provided.
|
|
149
|
+
*/
|
|
150
|
+
export declare function createDwebWorkflowsTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof workflowsSchema>;
|
|
151
|
+
declare const trendingAgentsSchema: z.ZodObject<{
|
|
152
|
+
window: z.ZodOptional<z.ZodEnum<["1h", "24h", "7d"]>>;
|
|
153
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
limit?: number | undefined;
|
|
156
|
+
window?: "1h" | "24h" | "7d" | undefined;
|
|
157
|
+
}, {
|
|
158
|
+
limit?: number | undefined;
|
|
159
|
+
window?: "1h" | "24h" | "7d" | undefined;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Trending agents tool.
|
|
163
|
+
*
|
|
164
|
+
* Wraps `client.getTrendingAgents(...)` — returns agents ranked by a
|
|
165
|
+
* multi-signal trending score (activity, capability changes, relationship
|
|
166
|
+
* growth, coordination quality).
|
|
167
|
+
*/
|
|
168
|
+
export declare function createTrendingAgentsTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof trendingAgentsSchema>;
|
|
169
|
+
declare const capabilityGraphSchema: z.ZodObject<{
|
|
170
|
+
q: z.ZodOptional<z.ZodString>;
|
|
171
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
172
|
+
}, "strip", z.ZodTypeAny, {
|
|
173
|
+
q?: string | undefined;
|
|
174
|
+
limit?: number | undefined;
|
|
175
|
+
}, {
|
|
176
|
+
q?: string | undefined;
|
|
177
|
+
limit?: number | undefined;
|
|
178
|
+
}>;
|
|
179
|
+
/**
|
|
180
|
+
* Capability graph search tool.
|
|
181
|
+
*
|
|
182
|
+
* Wraps `client.getCapabilities(...)` — answers "who provides capability X?"
|
|
183
|
+
* by querying the capability-provider graph.
|
|
184
|
+
*/
|
|
185
|
+
export declare function createCapabilitySearchTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof capabilityGraphSchema>;
|
|
186
|
+
declare const agentRecommendationSchema: z.ZodObject<{
|
|
187
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
188
|
+
q: z.ZodOptional<z.ZodString>;
|
|
189
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
}, "strip", z.ZodTypeAny, {
|
|
191
|
+
q?: string | undefined;
|
|
192
|
+
limit?: number | undefined;
|
|
193
|
+
capability?: string | undefined;
|
|
194
|
+
}, {
|
|
195
|
+
q?: string | undefined;
|
|
196
|
+
limit?: number | undefined;
|
|
197
|
+
capability?: string | undefined;
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Agent recommendation tool.
|
|
201
|
+
*
|
|
202
|
+
* Wraps `client.recommendAgents(...)` — recommends agents for a given
|
|
203
|
+
* capability or query, ranked by capability match, reputation, and
|
|
204
|
+
* recent activity.
|
|
205
|
+
*/
|
|
206
|
+
export declare function createAgentRecommendationTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof agentRecommendationSchema>;
|
|
207
|
+
declare const agentDirectorySchema: z.ZodObject<{
|
|
208
|
+
sort: z.ZodOptional<z.ZodEnum<["trending", "newest", "capability", "popularity"]>>;
|
|
209
|
+
capability: z.ZodOptional<z.ZodString>;
|
|
210
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
limit?: number | undefined;
|
|
213
|
+
sort?: "capability" | "trending" | "newest" | "popularity" | undefined;
|
|
214
|
+
capability?: string | undefined;
|
|
215
|
+
}, {
|
|
216
|
+
limit?: number | undefined;
|
|
217
|
+
sort?: "capability" | "trending" | "newest" | "popularity" | undefined;
|
|
218
|
+
capability?: string | undefined;
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* Agent directory tool — the "App Store" view of registered agents.
|
|
222
|
+
*
|
|
223
|
+
* Wraps `client.getAgentDirectory(...)` — returns a browsable directory
|
|
224
|
+
* of agents sortable by trending score, newest, or capability richness.
|
|
225
|
+
*/
|
|
226
|
+
export declare function createAgentDirectoryTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof agentDirectorySchema>;
|
|
227
|
+
declare const coordinationCandidatesSchema: z.ZodObject<{
|
|
228
|
+
task: z.ZodString;
|
|
229
|
+
capabilities: z.ZodOptional<z.ZodString>;
|
|
230
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
231
|
+
exclude_agent_id: z.ZodOptional<z.ZodString>;
|
|
232
|
+
min_confidence: z.ZodOptional<z.ZodNumber>;
|
|
233
|
+
min_trust: z.ZodOptional<z.ZodNumber>;
|
|
234
|
+
mode: z.ZodOptional<z.ZodEnum<["conservative", "balanced", "exploratory"]>>;
|
|
235
|
+
}, "strip", z.ZodTypeAny, {
|
|
236
|
+
task: string;
|
|
237
|
+
limit?: number | undefined;
|
|
238
|
+
capabilities?: string | undefined;
|
|
239
|
+
exclude_agent_id?: string | undefined;
|
|
240
|
+
min_confidence?: number | undefined;
|
|
241
|
+
min_trust?: number | undefined;
|
|
242
|
+
mode?: "conservative" | "balanced" | "exploratory" | undefined;
|
|
243
|
+
}, {
|
|
244
|
+
task: string;
|
|
245
|
+
limit?: number | undefined;
|
|
246
|
+
capabilities?: string | undefined;
|
|
247
|
+
exclude_agent_id?: string | undefined;
|
|
248
|
+
min_confidence?: number | undefined;
|
|
249
|
+
min_trust?: number | undefined;
|
|
250
|
+
mode?: "conservative" | "balanced" | "exploratory" | undefined;
|
|
251
|
+
}>;
|
|
252
|
+
/**
|
|
253
|
+
* Coordination candidates tool — task-to-team discovery.
|
|
254
|
+
*
|
|
255
|
+
* Wraps `client.getCoordinationCandidates(...)` — given a task description,
|
|
256
|
+
* returns ranked agents best suited to collaborate on that task.
|
|
257
|
+
*/
|
|
258
|
+
export declare function createCoordinationCandidatesTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof coordinationCandidatesSchema>;
|
|
259
|
+
declare const coordinationTeamSchema: z.ZodObject<{
|
|
260
|
+
task: z.ZodString;
|
|
261
|
+
capabilities: z.ZodOptional<z.ZodString>;
|
|
262
|
+
team_size: z.ZodOptional<z.ZodNumber>;
|
|
263
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
264
|
+
exclude_agent_id: z.ZodOptional<z.ZodString>;
|
|
265
|
+
min_confidence: z.ZodOptional<z.ZodNumber>;
|
|
266
|
+
min_trust: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
mode: z.ZodOptional<z.ZodEnum<["conservative", "balanced", "exploratory"]>>;
|
|
268
|
+
require_proven_collaboration: z.ZodOptional<z.ZodBoolean>;
|
|
269
|
+
}, "strip", z.ZodTypeAny, {
|
|
270
|
+
task: string;
|
|
271
|
+
limit?: number | undefined;
|
|
272
|
+
capabilities?: string | undefined;
|
|
273
|
+
exclude_agent_id?: string | undefined;
|
|
274
|
+
min_confidence?: number | undefined;
|
|
275
|
+
min_trust?: number | undefined;
|
|
276
|
+
mode?: "conservative" | "balanced" | "exploratory" | undefined;
|
|
277
|
+
team_size?: number | undefined;
|
|
278
|
+
require_proven_collaboration?: boolean | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
task: string;
|
|
281
|
+
limit?: number | undefined;
|
|
282
|
+
capabilities?: string | undefined;
|
|
283
|
+
exclude_agent_id?: string | undefined;
|
|
284
|
+
min_confidence?: number | undefined;
|
|
285
|
+
min_trust?: number | undefined;
|
|
286
|
+
mode?: "conservative" | "balanced" | "exploratory" | undefined;
|
|
287
|
+
team_size?: number | undefined;
|
|
288
|
+
require_proven_collaboration?: boolean | undefined;
|
|
289
|
+
}>;
|
|
290
|
+
/**
|
|
291
|
+
* Coordination team assembly tool — best small team for a task.
|
|
292
|
+
*
|
|
293
|
+
* Wraps `client.getCoordinationTeam(...)` — given a task description,
|
|
294
|
+
* assembles teams of agents that collectively cover the task's capability
|
|
295
|
+
* requirements, with coverage analysis and gap identification.
|
|
296
|
+
* **Advisory-only**: recommendations only; does not execute, dispatch, or assign work.
|
|
297
|
+
*/
|
|
298
|
+
export declare function createCoordinationTeamTool(clientOrConfig: DwebClient | DwebClientConfig): DynamicStructuredTool<typeof coordinationTeamSchema>;
|
|
299
|
+
export {};
|
|
300
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAajB,MAAM,8BAA8B,CAAC;AAetC,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;EAQf,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,WAAW,CAAC,CAW3C;AAMD,QAAA,MAAM,gBAAgB;;;;;;;;;;;;EAOpB,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,gBAAgB,CAAC,CAWhD;AAMD,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;EAKnB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAY/C;AAMD,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;EAMnB,CAAC;AAEH;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAa/C;AAMD,QAAA,MAAM,uBAAuB;;;;;;;;;;;;EAI3B,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,uBAAuB,CAAC,CAYvD;AAMD,QAAA,MAAM,eAAe;;;;;;;;;;;;EAInB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,eAAe,CAAC,CAY/C;AAMD,QAAA,MAAM,oBAAoB;;;;;;;;;EAMxB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,oBAAoB,CAAC,CAWpD;AAMD,QAAA,MAAM,qBAAqB;;;;;;;;;EAGzB,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,qBAAqB,CAAC,CAWrD;AAMD,QAAA,MAAM,yBAAyB;;;;;;;;;;;;EAI7B,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,yBAAyB,CAAC,CAYzD;AAMD,QAAA,MAAM,oBAAoB;;;;;;;;;;;;EAOxB,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,oBAAoB,CAAC,CAWpD;AAMD,QAAA,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;EAsBhC,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,4BAA4B,CAAC,CAc5D;AAMD,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuC1B,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,UAAU,GAAG,gBAAgB,GAC5C,qBAAqB,CAAC,OAAO,sBAAsB,CAAC,CActD"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bradyprotocol/discovery-langchain — LangChain tool factories for the Dweb Discovery Protocol.
|
|
3
|
+
*
|
|
4
|
+
* Each factory wraps a single @bradyprotocol/discovery-sdk method as a LangChain
|
|
5
|
+
* DynamicStructuredTool. Tools are advisory-only, non-executing, and carry
|
|
6
|
+
* no registration, identity, token, or stake assumptions.
|
|
7
|
+
*/
|
|
8
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { DwebClient } from "@bradyprotocol/discovery-sdk";
|
|
11
|
+
/* ------------------------------------------------------------------ */
|
|
12
|
+
/* Shared helper */
|
|
13
|
+
/* ------------------------------------------------------------------ */
|
|
14
|
+
function resolveClient(clientOrConfig) {
|
|
15
|
+
if (clientOrConfig instanceof DwebClient)
|
|
16
|
+
return clientOrConfig;
|
|
17
|
+
return new DwebClient(clientOrConfig);
|
|
18
|
+
}
|
|
19
|
+
/* ------------------------------------------------------------------ */
|
|
20
|
+
/* 1. Query */
|
|
21
|
+
/* ------------------------------------------------------------------ */
|
|
22
|
+
const querySchema = z.object({
|
|
23
|
+
q: z.string().describe("Natural-language discovery query"),
|
|
24
|
+
limit: z.number().int().positive().optional().describe("Max results to return"),
|
|
25
|
+
entity_types: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Comma-separated entity types to filter (e.g. 'agent,capability')"),
|
|
29
|
+
capabilities: z.string().optional().describe("Comma-separated capabilities to filter by"),
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Universal discovery query tool.
|
|
33
|
+
*
|
|
34
|
+
* Wraps `client.query(...)` — returns recommended agents, related
|
|
35
|
+
* capabilities, suggested workflows, and trending matches.
|
|
36
|
+
*/
|
|
37
|
+
export function createDwebQueryTool(clientOrConfig) {
|
|
38
|
+
const client = resolveClient(clientOrConfig);
|
|
39
|
+
return new DynamicStructuredTool({
|
|
40
|
+
name: "dweb_query",
|
|
41
|
+
description: "Search the Dweb Discovery Protocol for agents, capabilities, and workflows. " +
|
|
42
|
+
"Returns advisory recommendations — signals, not directives.",
|
|
43
|
+
schema: querySchema,
|
|
44
|
+
func: async (input) => client.query(input),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/* ------------------------------------------------------------------ */
|
|
48
|
+
/* 2. Capability Search */
|
|
49
|
+
/* ------------------------------------------------------------------ */
|
|
50
|
+
const capabilitySchema = z.object({
|
|
51
|
+
q: z.string().describe("Capability keyword search query"),
|
|
52
|
+
limit: z.number().int().positive().optional().describe("Max results to return"),
|
|
53
|
+
include_related: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Set to 'true' to include related/co-occurring capabilities"),
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Capability keyword search tool.
|
|
60
|
+
*
|
|
61
|
+
* Wraps `client.searchCapability(...)` — returns matching capabilities,
|
|
62
|
+
* related agents, and co-occurrence intelligence.
|
|
63
|
+
*/
|
|
64
|
+
export function createDwebCapabilityTool(clientOrConfig) {
|
|
65
|
+
const client = resolveClient(clientOrConfig);
|
|
66
|
+
return new DynamicStructuredTool({
|
|
67
|
+
name: "dweb_capability_search",
|
|
68
|
+
description: "Search for agent capabilities in the Dweb protocol by keyword. " +
|
|
69
|
+
"Returns matching capabilities with agent counts and co-occurrence data.",
|
|
70
|
+
schema: capabilitySchema,
|
|
71
|
+
func: async (input) => client.searchCapability(input),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/* ------------------------------------------------------------------ */
|
|
75
|
+
/* 3. Recommend */
|
|
76
|
+
/* ------------------------------------------------------------------ */
|
|
77
|
+
const recommendSchema = z.object({
|
|
78
|
+
agent_id: z.string().optional().describe("Agent ID to get recommendations for"),
|
|
79
|
+
capability: z.string().optional().describe("Capability to get recommendations for"),
|
|
80
|
+
q: z.string().optional().describe("Natural-language recommendation query"),
|
|
81
|
+
limit: z.number().int().positive().optional().describe("Max results to return"),
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Unified advisory recommendation tool.
|
|
85
|
+
*
|
|
86
|
+
* Wraps `client.recommend(...)` — composes agents, collaborators,
|
|
87
|
+
* workflows, and capabilities into a single recommendation response.
|
|
88
|
+
* At least one of agent_id, capability, or q must be provided.
|
|
89
|
+
*/
|
|
90
|
+
export function createDwebRecommendTool(clientOrConfig) {
|
|
91
|
+
const client = resolveClient(clientOrConfig);
|
|
92
|
+
return new DynamicStructuredTool({
|
|
93
|
+
name: "dweb_recommend",
|
|
94
|
+
description: "Get unified advisory recommendations from the Dweb protocol. " +
|
|
95
|
+
"Combines agent, collaborator, workflow, and capability signals. " +
|
|
96
|
+
"Provide at least one of: agent_id, capability, or q.",
|
|
97
|
+
schema: recommendSchema,
|
|
98
|
+
func: async (input) => client.recommend(input),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/* ------------------------------------------------------------------ */
|
|
102
|
+
/* 4. Route Task (advisory-only) */
|
|
103
|
+
/* ------------------------------------------------------------------ */
|
|
104
|
+
const routeTaskSchema = z.object({
|
|
105
|
+
task: z.string().optional().describe("Task description to route"),
|
|
106
|
+
goal: z.string().optional().describe("High-level goal for the task"),
|
|
107
|
+
capabilities: z.array(z.string()).optional().describe("Required capabilities for the task"),
|
|
108
|
+
agent_id: z.string().optional().describe("Preferred agent ID"),
|
|
109
|
+
context: z.record(z.string(), z.unknown()).optional().describe("Additional context for routing"),
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Advisory task-to-pipeline routing tool.
|
|
113
|
+
*
|
|
114
|
+
* Wraps `client.routeTask(...)` — suggests an execution pipeline for a
|
|
115
|
+
* task. **Advisory-only**: this tool does NOT execute, dispatch, reserve,
|
|
116
|
+
* or lock anything. The recommendation is a signal; the calling agent
|
|
117
|
+
* decides whether and how to act on it.
|
|
118
|
+
*
|
|
119
|
+
* At least one of task, goal, capabilities, or agent_id must be provided.
|
|
120
|
+
*/
|
|
121
|
+
export function createDwebRouteTaskTool(clientOrConfig) {
|
|
122
|
+
const client = resolveClient(clientOrConfig);
|
|
123
|
+
return new DynamicStructuredTool({
|
|
124
|
+
name: "dweb_route_task",
|
|
125
|
+
description: "Get an advisory routing recommendation for a task from the Dweb protocol. " +
|
|
126
|
+
"ADVISORY ONLY — does NOT execute, dispatch, reserve, or lock anything. " +
|
|
127
|
+
"Returns suggested agents, pipeline steps, collaborators, and confidence. " +
|
|
128
|
+
"Provide at least one of: task, goal, capabilities, or agent_id.",
|
|
129
|
+
schema: routeTaskSchema,
|
|
130
|
+
func: async (input) => client.routeTask(input),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/* ------------------------------------------------------------------ */
|
|
134
|
+
/* 5. Best Collaborators (optional) */
|
|
135
|
+
/* ------------------------------------------------------------------ */
|
|
136
|
+
const bestCollaboratorsSchema = z.object({
|
|
137
|
+
agent_id: z.string().optional().describe("Agent ID to find collaborators for"),
|
|
138
|
+
capability: z.string().optional().describe("Capability to find collaborators for"),
|
|
139
|
+
limit: z.number().int().positive().optional().describe("Max results to return"),
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Best collaborator recommendations tool.
|
|
143
|
+
*
|
|
144
|
+
* Wraps `client.getBestCollaborators(...)` — returns collaborator
|
|
145
|
+
* candidates ranked by trust, coordination quality, and shared capabilities.
|
|
146
|
+
* At least one of agent_id or capability must be provided.
|
|
147
|
+
*/
|
|
148
|
+
export function createDwebBestCollaboratorsTool(clientOrConfig) {
|
|
149
|
+
const client = resolveClient(clientOrConfig);
|
|
150
|
+
return new DynamicStructuredTool({
|
|
151
|
+
name: "dweb_best_collaborators",
|
|
152
|
+
description: "Find the best collaborator agents from the Dweb protocol. " +
|
|
153
|
+
"Returns candidates ranked by trust, coordination quality, and shared capabilities. " +
|
|
154
|
+
"Provide at least one of: agent_id or capability.",
|
|
155
|
+
schema: bestCollaboratorsSchema,
|
|
156
|
+
func: async (input) => client.getBestCollaborators(input),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/* ------------------------------------------------------------------ */
|
|
160
|
+
/* 6. Workflows (optional) */
|
|
161
|
+
/* ------------------------------------------------------------------ */
|
|
162
|
+
const workflowsSchema = z.object({
|
|
163
|
+
capability: z.string().optional().describe("Capability to find workflow patterns for"),
|
|
164
|
+
agent_id: z.string().optional().describe("Agent ID to find workflow patterns for"),
|
|
165
|
+
limit: z.number().int().positive().optional().describe("Max results to return"),
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* Learned workflow patterns tool.
|
|
169
|
+
*
|
|
170
|
+
* Wraps `client.getWorkflows(...)` — returns multi-agent workflow patterns
|
|
171
|
+
* extracted from coordination outcome data.
|
|
172
|
+
* At least one of capability or agent_id must be provided.
|
|
173
|
+
*/
|
|
174
|
+
export function createDwebWorkflowsTool(clientOrConfig) {
|
|
175
|
+
const client = resolveClient(clientOrConfig);
|
|
176
|
+
return new DynamicStructuredTool({
|
|
177
|
+
name: "dweb_workflows",
|
|
178
|
+
description: "Discover learned multi-agent workflow patterns from the Dweb protocol. " +
|
|
179
|
+
"Returns patterns with success rates, frequency, and evidence depth. " +
|
|
180
|
+
"Provide at least one of: capability or agent_id.",
|
|
181
|
+
schema: workflowsSchema,
|
|
182
|
+
func: async (input) => client.getWorkflows(input),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/* ------------------------------------------------------------------ */
|
|
186
|
+
/* 7. Trending Agents (Phase 9) */
|
|
187
|
+
/* ------------------------------------------------------------------ */
|
|
188
|
+
const trendingAgentsSchema = z.object({
|
|
189
|
+
window: z
|
|
190
|
+
.enum(["1h", "24h", "7d"])
|
|
191
|
+
.optional()
|
|
192
|
+
.describe("Time window for trending data (default: 24h)"),
|
|
193
|
+
limit: z.number().int().positive().optional().describe("Max agents to return"),
|
|
194
|
+
});
|
|
195
|
+
/**
|
|
196
|
+
* Trending agents tool.
|
|
197
|
+
*
|
|
198
|
+
* Wraps `client.getTrendingAgents(...)` — returns agents ranked by a
|
|
199
|
+
* multi-signal trending score (activity, capability changes, relationship
|
|
200
|
+
* growth, coordination quality).
|
|
201
|
+
*/
|
|
202
|
+
export function createTrendingAgentsTool(clientOrConfig) {
|
|
203
|
+
const client = resolveClient(clientOrConfig);
|
|
204
|
+
return new DynamicStructuredTool({
|
|
205
|
+
name: "dweb_trending_agents",
|
|
206
|
+
description: "Get trending agents from the Dweb protocol ranked by multi-signal score " +
|
|
207
|
+
"(activity velocity, capability changes, relationship growth, coordination quality).",
|
|
208
|
+
schema: trendingAgentsSchema,
|
|
209
|
+
func: async (input) => client.getTrendingAgents(input),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/* ------------------------------------------------------------------ */
|
|
213
|
+
/* 8. Capability Graph Search (Phase 9) */
|
|
214
|
+
/* ------------------------------------------------------------------ */
|
|
215
|
+
const capabilityGraphSchema = z.object({
|
|
216
|
+
q: z.string().optional().describe("Keyword filter to search capabilities"),
|
|
217
|
+
limit: z.number().int().positive().optional().describe("Max capabilities to return"),
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* Capability graph search tool.
|
|
221
|
+
*
|
|
222
|
+
* Wraps `client.getCapabilities(...)` — answers "who provides capability X?"
|
|
223
|
+
* by querying the capability-provider graph.
|
|
224
|
+
*/
|
|
225
|
+
export function createCapabilitySearchTool(clientOrConfig) {
|
|
226
|
+
const client = resolveClient(clientOrConfig);
|
|
227
|
+
return new DynamicStructuredTool({
|
|
228
|
+
name: "dweb_capability_graph",
|
|
229
|
+
description: "Search the Dweb capability graph to find which agents provide a given capability. " +
|
|
230
|
+
"Returns capabilities with their provider agents.",
|
|
231
|
+
schema: capabilityGraphSchema,
|
|
232
|
+
func: async (input) => client.getCapabilities(input),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/* ------------------------------------------------------------------ */
|
|
236
|
+
/* 9. Agent Recommendations (Phase 9) */
|
|
237
|
+
/* ------------------------------------------------------------------ */
|
|
238
|
+
const agentRecommendationSchema = z.object({
|
|
239
|
+
capability: z.string().optional().describe("Capability to find agents for"),
|
|
240
|
+
q: z.string().optional().describe("Keyword search for agents"),
|
|
241
|
+
limit: z.number().int().positive().optional().describe("Max agents to return"),
|
|
242
|
+
});
|
|
243
|
+
/**
|
|
244
|
+
* Agent recommendation tool.
|
|
245
|
+
*
|
|
246
|
+
* Wraps `client.recommendAgents(...)` — recommends agents for a given
|
|
247
|
+
* capability or query, ranked by capability match, reputation, and
|
|
248
|
+
* recent activity.
|
|
249
|
+
*/
|
|
250
|
+
export function createAgentRecommendationTool(clientOrConfig) {
|
|
251
|
+
const client = resolveClient(clientOrConfig);
|
|
252
|
+
return new DynamicStructuredTool({
|
|
253
|
+
name: "dweb_agent_recommendation",
|
|
254
|
+
description: "Get agent recommendations from the Dweb protocol for a given capability or query. " +
|
|
255
|
+
"Agents are ranked by capability match, ecosystem reputation, and recent activity. " +
|
|
256
|
+
"Provide at least one of: capability or q.",
|
|
257
|
+
schema: agentRecommendationSchema,
|
|
258
|
+
func: async (input) => client.recommendAgents(input),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/* ------------------------------------------------------------------ */
|
|
262
|
+
/* 10. Agent Directory (Phase 9) */
|
|
263
|
+
/* ------------------------------------------------------------------ */
|
|
264
|
+
const agentDirectorySchema = z.object({
|
|
265
|
+
sort: z
|
|
266
|
+
.enum(["trending", "newest", "capability", "popularity"])
|
|
267
|
+
.optional()
|
|
268
|
+
.describe("Sort order (default: trending)"),
|
|
269
|
+
capability: z.string().optional().describe("Filter agents by capability"),
|
|
270
|
+
limit: z.number().int().positive().optional().describe("Max agents to return"),
|
|
271
|
+
});
|
|
272
|
+
/**
|
|
273
|
+
* Agent directory tool — the "App Store" view of registered agents.
|
|
274
|
+
*
|
|
275
|
+
* Wraps `client.getAgentDirectory(...)` — returns a browsable directory
|
|
276
|
+
* of agents sortable by trending score, newest, or capability richness.
|
|
277
|
+
*/
|
|
278
|
+
export function createAgentDirectoryTool(clientOrConfig) {
|
|
279
|
+
const client = resolveClient(clientOrConfig);
|
|
280
|
+
return new DynamicStructuredTool({
|
|
281
|
+
name: "dweb_agent_directory",
|
|
282
|
+
description: "Browse the Dweb agent directory — an App Store-like view of registered agents. " +
|
|
283
|
+
"Sortable by trending score, newest, or capability richness.",
|
|
284
|
+
schema: agentDirectorySchema,
|
|
285
|
+
func: async (input) => client.getAgentDirectory(input),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/* ------------------------------------------------------------------ */
|
|
289
|
+
/* 11. Coordination Candidates (Phase 10) */
|
|
290
|
+
/* ------------------------------------------------------------------ */
|
|
291
|
+
const coordinationCandidatesSchema = z.object({
|
|
292
|
+
task: z.string().describe("Task or goal description to find collaborators for"),
|
|
293
|
+
capabilities: z.string().optional().describe("Comma-separated required capabilities"),
|
|
294
|
+
limit: z.number().int().positive().optional().describe("Max candidates to return"),
|
|
295
|
+
exclude_agent_id: z.string().optional().describe("Agent ID to exclude from results (e.g. self)"),
|
|
296
|
+
min_confidence: z
|
|
297
|
+
.number()
|
|
298
|
+
.min(0)
|
|
299
|
+
.max(1)
|
|
300
|
+
.optional()
|
|
301
|
+
.describe("Slice 8 - Minimum candidate score 0-1; filters below threshold"),
|
|
302
|
+
min_trust: z
|
|
303
|
+
.number()
|
|
304
|
+
.int()
|
|
305
|
+
.min(0)
|
|
306
|
+
.max(100)
|
|
307
|
+
.optional()
|
|
308
|
+
.describe("Slice 8 - Minimum trust_score 0-100"),
|
|
309
|
+
mode: z
|
|
310
|
+
.enum(["conservative", "balanced", "exploratory"])
|
|
311
|
+
.optional()
|
|
312
|
+
.describe("Slice 8 - conservative=stricter; exploratory=more permissive"),
|
|
313
|
+
});
|
|
314
|
+
/**
|
|
315
|
+
* Coordination candidates tool — task-to-team discovery.
|
|
316
|
+
*
|
|
317
|
+
* Wraps `client.getCoordinationCandidates(...)` — given a task description,
|
|
318
|
+
* returns ranked agents best suited to collaborate on that task.
|
|
319
|
+
*/
|
|
320
|
+
export function createCoordinationCandidatesTool(clientOrConfig) {
|
|
321
|
+
const client = resolveClient(clientOrConfig);
|
|
322
|
+
return new DynamicStructuredTool({
|
|
323
|
+
name: "dweb_coordination_candidates",
|
|
324
|
+
description: "Find agents best suited to collaborate on a task using the Dweb protocol. " +
|
|
325
|
+
"Given a task description, returns ranked coordination candidates with " +
|
|
326
|
+
"match reasoning, trust scores, coordination signals, best_for label, " +
|
|
327
|
+
"selection_summary, strengths, weaknesses, and optional tradeoff_summary. " +
|
|
328
|
+
"Slice 8: min_confidence, min_trust, mode. Slice 9: marketplace comparison. Slice 10: primary_recommendation, decision_summary, recommended_first. Slice 11: handoff_summary.",
|
|
329
|
+
schema: coordinationCandidatesSchema,
|
|
330
|
+
func: async (input) => client.getCoordinationCandidates(input),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/* ------------------------------------------------------------------ */
|
|
334
|
+
/* 12. Coordination Team (Phase 10.2) */
|
|
335
|
+
/* ------------------------------------------------------------------ */
|
|
336
|
+
const coordinationTeamSchema = z.object({
|
|
337
|
+
task: z.string().describe("Task or goal description to assemble a team for"),
|
|
338
|
+
capabilities: z.string().optional().describe("Comma-separated required capabilities"),
|
|
339
|
+
team_size: z
|
|
340
|
+
.number()
|
|
341
|
+
.int()
|
|
342
|
+
.min(2)
|
|
343
|
+
.max(5)
|
|
344
|
+
.optional()
|
|
345
|
+
.describe("Desired team size (2–5, default: 3)"),
|
|
346
|
+
limit: z
|
|
347
|
+
.number()
|
|
348
|
+
.int()
|
|
349
|
+
.min(1)
|
|
350
|
+
.max(5)
|
|
351
|
+
.optional()
|
|
352
|
+
.describe("Max alternative teams to return (1–5, default: 3)"),
|
|
353
|
+
exclude_agent_id: z.string().optional().describe("Agent ID to exclude from results (e.g. self)"),
|
|
354
|
+
min_confidence: z
|
|
355
|
+
.number()
|
|
356
|
+
.min(0)
|
|
357
|
+
.max(1)
|
|
358
|
+
.optional()
|
|
359
|
+
.describe("Slice 8 - Minimum team confidence 0-1"),
|
|
360
|
+
min_trust: z
|
|
361
|
+
.number()
|
|
362
|
+
.int()
|
|
363
|
+
.min(0)
|
|
364
|
+
.max(100)
|
|
365
|
+
.optional()
|
|
366
|
+
.describe("Slice 8 - Minimum member trust_score 0-100"),
|
|
367
|
+
mode: z
|
|
368
|
+
.enum(["conservative", "balanced", "exploratory"])
|
|
369
|
+
.optional()
|
|
370
|
+
.describe("Slice 8 - conservative=stricter; exploratory=more permissive"),
|
|
371
|
+
require_proven_collaboration: z
|
|
372
|
+
.boolean()
|
|
373
|
+
.optional()
|
|
374
|
+
.describe("Slice 8 - Only teams with pairwise collaboration history"),
|
|
375
|
+
});
|
|
376
|
+
/**
|
|
377
|
+
* Coordination team assembly tool — best small team for a task.
|
|
378
|
+
*
|
|
379
|
+
* Wraps `client.getCoordinationTeam(...)` — given a task description,
|
|
380
|
+
* assembles teams of agents that collectively cover the task's capability
|
|
381
|
+
* requirements, with coverage analysis and gap identification.
|
|
382
|
+
* **Advisory-only**: recommendations only; does not execute, dispatch, or assign work.
|
|
383
|
+
*/
|
|
384
|
+
export function createCoordinationTeamTool(clientOrConfig) {
|
|
385
|
+
const client = resolveClient(clientOrConfig);
|
|
386
|
+
return new DynamicStructuredTool({
|
|
387
|
+
name: "dweb_coordination_team",
|
|
388
|
+
description: "Advisory-only — assemble the best small team of agents for a task using the Dweb protocol. " +
|
|
389
|
+
"Returns assembled teams with per-member roles, coverage analysis, alternate " +
|
|
390
|
+
"candidates (with why_not_higher), confidence, guidance, best_for, " +
|
|
391
|
+
"selection_summary, strengths, weaknesses, and optional tradeoff_summary. " +
|
|
392
|
+
"Slice 8: min_confidence, min_trust, mode. Slice 9: marketplace comparison. Slice 10: primary_recommendation, decision_summary, recommended_first. Slice 11: handoff_summary, engage_first_member.",
|
|
393
|
+
schema: coordinationTeamSchema,
|
|
394
|
+
func: async (input) => client.getCoordinationTeam(input),
|
|
395
|
+
});
|
|
396
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bradyprotocol/discovery-langchain",
|
|
3
|
+
"version": "0.2.5",
|
|
4
|
+
"description": "LangChain tool adapter for the BRADY Discovery Protocol — wraps @bradyprotocol/discovery-sdk",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/SerDaboz/Dweb-Discoverer.git",
|
|
10
|
+
"directory": "packages/langchain"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://bradyprotocol.xyz",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/SerDaboz/Dweb-Discoverer/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc -b",
|
|
31
|
+
"prepublishOnly": "bun run build",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest",
|
|
34
|
+
"lint": "eslint src/",
|
|
35
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
36
|
+
"format:check": "prettier --check \"src/**/*.ts\""
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@bradyprotocol/discovery-sdk": "^0.2.4",
|
|
40
|
+
"@langchain/core": ">=0.3.0",
|
|
41
|
+
"zod": ">=3.22.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@bradyprotocol/discovery-sdk": "workspace:*",
|
|
45
|
+
"@langchain/core": "^1.1.20",
|
|
46
|
+
"typescript": "^5.6.0",
|
|
47
|
+
"vitest": "^4.0.0",
|
|
48
|
+
"prettier": "^3.8.0",
|
|
49
|
+
"zod": "^3.25.0"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"dweb",
|
|
53
|
+
"langchain",
|
|
54
|
+
"agent",
|
|
55
|
+
"tools",
|
|
56
|
+
"discovery",
|
|
57
|
+
"web3",
|
|
58
|
+
"decentralized"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"sideEffects": false,
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18"
|
|
66
|
+
}
|
|
67
|
+
}
|