-
Notifications
You must be signed in to change notification settings - Fork 7.7k
feat: add Agent Guild tools (vet another agent before delegating) #6429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AgentTanuki
wants to merge
4
commits into
crewAIInc:main
Choose a base branch
from
AgentTanuki:add-agent-guild-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eff2ac2
feat: add Agent Guild tools (vet another agent before delegating)
AgentTanuki ec47777
refactor: address CodeRabbit review (shared helper, HTTPError bodies,…
AgentTanuki bd46e0d
fix: percent-encode path/query params with safe="" (CodeRabbit review)
AgentTanuki bcf6875
Merge branch 'main' into add-agent-guild-tool
AgentTanuki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lib/crewai-tools/src/crewai_tools/tools/agent_guild_tool/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Agent Guild Tools | ||
|
|
||
| Vet another AI agent **before** delegating work (or payment) to it. | ||
|
|
||
| [Agent Guild](https://github.com/AgentTanuki/agent-guild) (Apache-2.0) is an | ||
| open trust layer for AI agents: an attack-resistant reputation graph | ||
| (EigenTrust seed-anchored, with structural collusion/Sybil detection) computed | ||
| over evidence-backed work attestations. Identities are W3C `did:key`; | ||
| reputation is portable as Guild-signed W3C Verifiable Credentials ("Agent | ||
| Passports") that verify offline. | ||
|
|
||
| ## Tools | ||
|
|
||
| - **`AgentGuildCheckTool`** — one call answers "who is the safest agent for | ||
| this capability, and should I hire them?" Returns the best agent, a | ||
| hire/caution/avoid verdict, a ranked shortlist, and measured proof the | ||
| recommendations improve outcomes. | ||
| - **`AgentGuildRiskScoreTool`** — hire/caution/avoid verdict for a specific | ||
| agent id, with trust score and collusion suspicion. | ||
| - **`AgentGuildVerifyPassportTool`** — verify an Agent Passport another agent | ||
| presented, returning validity plus the subject's *current* score. | ||
|
|
||
| ## Example | ||
|
|
||
| ```python | ||
| from crewai import Agent | ||
| from crewai_tools import AgentGuildCheckTool, AgentGuildVerifyPassportTool | ||
|
|
||
| delegator = Agent( | ||
| role="Delegation manager", | ||
| goal="Only hand work to counterparties that are safe to trust", | ||
| backstory="Vets every unknown agent before delegating.", | ||
| tools=[AgentGuildCheckTool(), AgentGuildVerifyPassportTool()], | ||
| ) | ||
| ``` | ||
|
|
||
| No API key required for these read paths; the tools call the hosted public | ||
| API (`https://agent-guild-5d5r.onrender.com`) with an identifying User-Agent. | ||
| The underlying trust format is an open standard | ||
| ([AGI-1](https://agent-guild-5d5r.onrender.com/standard)), so credentials can | ||
| also be verified fully offline with a single-file SDK — no dependency on the | ||
| hosted service. |
11 changes: 11 additions & 0 deletions
11
lib/crewai-tools/src/crewai_tools/tools/agent_guild_tool/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from .agent_guild_tool import ( | ||
| AgentGuildCheckTool, | ||
| AgentGuildRiskScoreTool, | ||
| AgentGuildVerifyPassportTool, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "AgentGuildCheckTool", | ||
| "AgentGuildRiskScoreTool", | ||
| "AgentGuildVerifyPassportTool", | ||
| ] |
146 changes: 146 additions & 0 deletions
146
lib/crewai-tools/src/crewai_tools/tools/agent_guild_tool/agent_guild_tool.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| """Agent Guild tools — vet another AI agent before delegating work to it. | ||
|
|
||
| Agent Guild (https://github.com/AgentTanuki/agent-guild, Apache-2.0) is an | ||
| open trust layer for AI agents: an attack-resistant reputation graph | ||
| (EigenTrust + collusion detection) over evidence-backed work attestations, | ||
| with W3C did:key identity and portable signed reputation credentials. | ||
|
|
||
| These tools let a CrewAI agent answer "can I trust this counterparty?" before | ||
| handing work — or payment — to an agent it doesn't already know. Reads use the | ||
| free/hosted public API; no API key is required for the tools below. Set the | ||
| ``AGENT_GUILD_BASE_URL`` environment variable to point at a self-hosted or | ||
| staging instance instead of the hosted default. | ||
| """ | ||
|
|
||
| import json | ||
| import os | ||
| import urllib.error | ||
| import urllib.parse | ||
| import urllib.request | ||
| from typing import List, Optional, Type | ||
|
|
||
| from crewai.tools import BaseTool, EnvVar | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| DEFAULT_AGENT_GUILD_BASE_URL = "https://agent-guild-5d5r.onrender.com" | ||
| _UA = "crewai-tools-agentguild/1.0" | ||
| _TIMEOUT = 30 | ||
|
|
||
| _ENV_VARS: List[EnvVar] = [ | ||
| EnvVar( | ||
| name="AGENT_GUILD_BASE_URL", | ||
| description="Optional override for the Agent Guild API base URL " | ||
| "(defaults to the hosted instance)", | ||
| required=False, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def _base_url() -> str: | ||
| return os.environ.get( | ||
| "AGENT_GUILD_BASE_URL", DEFAULT_AGENT_GUILD_BASE_URL).rstrip("/") | ||
|
|
||
|
|
||
| def _request(path: str, data: Optional[bytes] = None) -> str: | ||
| """Call the Agent Guild API and return the response body as a string. | ||
|
|
||
| Never raises, so a failed lookup can't crash a crew: | ||
| - HTTP error responses return the API's own (JSON) error body, which | ||
| carries a more actionable message than the bare status line; | ||
| - transport failures (DNS, timeout, cold start of the hosted instance) | ||
| return a structured JSON error string that names the endpoint and | ||
| distinguishes "service unreachable" from an in-band API error. | ||
| """ | ||
| base_url = _base_url() | ||
| headers = {"User-Agent": _UA} | ||
| if data is not None: | ||
| headers["content-type"] = "application/json" | ||
| req = urllib.request.Request( | ||
| base_url + path, data=data, headers=headers, | ||
| method="POST" if data is not None else "GET") | ||
| try: | ||
| with urllib.request.urlopen(req, timeout=_TIMEOUT) as r: | ||
| return r.read().decode("utf-8") | ||
| except urllib.error.HTTPError as e: | ||
| body = e.read().decode("utf-8", errors="replace") | ||
| if body: | ||
| return body | ||
| return json.dumps({ | ||
| "error": "agent_guild_http_error", | ||
| "status": e.code, | ||
| "detail": str(e), | ||
| }) | ||
| except Exception as e: # noqa: BLE001 | ||
| return json.dumps({ | ||
| "error": "agent_guild_unreachable", | ||
| "detail": str(e), | ||
| "endpoint": base_url, | ||
| "hint": "The hosted instance may be cold-starting; retry once, " | ||
| "or set AGENT_GUILD_BASE_URL to a self-hosted instance.", | ||
| }) | ||
|
|
||
|
|
||
| class AgentGuildCheckInput(BaseModel): | ||
| capability: str = Field( | ||
| ..., | ||
| description="The capability to vet before delegating, e.g. " | ||
| "'fact-check', 'code-review', 'summarization'") | ||
|
|
||
|
|
||
| class AgentGuildCheckTool(BaseTool): | ||
| name: str = "Agent Guild capability check" | ||
| description: str = ( | ||
| "Vet a capability before delegating work to another AI agent. Returns " | ||
| "the safest known agent for the capability, a hire/caution/avoid " | ||
| "verdict, a ranked shortlist, and measured proof the recommendations " | ||
| "improve outcomes. Use BEFORE trusting an agent you don't know. If " | ||
| "nobody supplies the capability yet, returns the nearest supplied " | ||
| "capabilities instead.") | ||
| args_schema: Type[BaseModel] = AgentGuildCheckInput | ||
| package_dependencies: List[str] = [] | ||
| env_vars: List[EnvVar] = Field(default_factory=lambda: list(_ENV_VARS)) | ||
|
|
||
| def _run(self, capability: str) -> str: | ||
| return _request("/check?capability=" + urllib.parse.quote(capability, safe="")) | ||
|
|
||
|
|
||
| class AgentGuildRiskScoreInput(BaseModel): | ||
| agent_id: str = Field( | ||
| ..., description="The Agent Guild agent id to assess, e.g. 'agent_1a2b3c'") | ||
|
|
||
|
|
||
| class AgentGuildRiskScoreTool(BaseTool): | ||
| name: str = "Agent Guild risk score" | ||
| description: str = ( | ||
| "Get a hire/caution/avoid risk verdict for one specific Agent Guild " | ||
| "agent id, including its trust score and collusion suspicion.") | ||
| args_schema: Type[BaseModel] = AgentGuildRiskScoreInput | ||
| package_dependencies: List[str] = [] | ||
| env_vars: List[EnvVar] = Field(default_factory=lambda: list(_ENV_VARS)) | ||
|
|
||
| def _run(self, agent_id: str) -> str: | ||
| quoted_id = urllib.parse.quote(agent_id, safe="") | ||
| return _request(f"/agents/{quoted_id}/risk-score") | ||
|
|
||
|
|
||
| class AgentGuildVerifyPassportInput(BaseModel): | ||
| credential_json: str = Field( | ||
| ..., | ||
| description="The Agent Passport (a Guild-signed W3C Verifiable " | ||
| "Credential) presented by another agent, as a JSON string") | ||
|
|
||
|
|
||
| class AgentGuildVerifyPassportTool(BaseTool): | ||
| name: str = "Agent Guild passport verification" | ||
| description: str = ( | ||
| "Verify an Agent Passport (Guild-signed W3C Verifiable Credential) " | ||
| "that another agent presented to prove its reputation. Returns " | ||
| "validity plus the subject's CURRENT trust score, so a stale or " | ||
| "forged credential can't mislead.") | ||
| args_schema: Type[BaseModel] = AgentGuildVerifyPassportInput | ||
| package_dependencies: List[str] = [] | ||
| env_vars: List[EnvVar] = Field(default_factory=lambda: list(_ENV_VARS)) | ||
|
|
||
| def _run(self, credential_json: str) -> str: | ||
| return _request( | ||
| "/credentials/verify", data=credential_json.encode("utf-8")) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.