Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ dailybot_cli/ # Source package
├── version.py # `dailybot version` — install info + PyPI update check
├── upgrade.py # `dailybot upgrade` — auto-detect install method + self-update
├── uninstall.py # `dailybot uninstall` — auto-detect install method + remove
└── agent.py # `agent` group: configure, profiles, register,
# update, health, webhook, message, email
├── agent.py # `agent` group: configure, profiles, register,
│ # update, health, webhook, message, email
└── agent_messenger.py # `agent connect / me / ask / replies`, `agent webhook
# set|show|remove` (agent credential, /v1/messaging/agents/)

tests/ # pytest suite (file naming: *_test.py)
├── api_client_test.py # HTTP client mocking (all DailyBotClient methods)
Expand Down Expand Up @@ -176,6 +178,7 @@ tests/ # pytest suite (file naming: *_test.py)
├── milestones_updates_test.py # milestone attachments/restore; project update get/edit/delete/attachments
├── tasks_reactions_test.py # reactions: who reacted, project-update react/unreact, full reactor lists
├── transport_errors_test.py # transport failures render as messages, not tracebacks
├── agent_messenger_test.py # agent messenger: store, wire (Agent scheme, no fallback), commands
└── config_test.py # Config/credential file management

.github/workflows/release.yml # Tag-triggered: PyPI + Linux binary + Homebrew
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,21 @@ Once installed, your agent **auto-routes by intent** — "report this to Dailybo

> This repo **dogfoods** the skill: the pack is vendored at [`.agents/skills/dailybot/`](.agents/skills/dailybot/) so any agent working on the CLI uses it too.

### Ask a person and wait for the answer

An agent can ask you (or a teammate) a question through Dailybot and wait for the reply — a one-tap decision when you give options. Organizations on the new Dailybot only.

```bash
dailybot login # once, as the person who owns the agent
dailybot agent connect "Release bot" # once: stores the agent credential (mode 600)

dailybot agent ask --to me@example.com "Deploy to production now?" \
--option Yes --option "Not yet" --wait 30m --json # exit 0 answered, 124 timed out

dailybot agent replies --wait 10m # answers since the last call
dailybot agent webhook set https://my-agent.example.com/dailybot # or get them pushed (signed)
```

### Quick start (interactive)

If you only do one thing on a fresh install, run:
Expand Down Expand Up @@ -1213,6 +1228,11 @@ same delivery path as `chat send`).
| `dailybot agent register` | Register a new agent and organization (standalone) |
| `dailybot agent update` | Submit an agent activity report |
| `dailybot agent health` | Report or query agent health status |
| `dailybot agent connect "<name>"` | Connect an agent you own so it can message people (needs `dailybot login`) |
| `dailybot agent me` | Show the agent behind the stored messenger credential |
| `dailybot agent ask --to <email> "<text>"` | Ask a person; `--option` for a one-tap decision, `--wait` to block for the answer |
| `dailybot agent replies` | Answers since the last call (`--wait`, `--follow`) |
| `dailybot agent webhook set <url>` / `show` / `remove` | The messenger webhook (signed with `X-Dailybot-Signature`) |
| `dailybot agent webhook register` | Register a webhook for the agent |
| `dailybot agent webhook unregister` | Unregister the agent's webhook |
| `dailybot agent message send` | Send a message to an agent |
Expand Down
152 changes: 152 additions & 0 deletions dailybot_cli/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ def _fill_meta(meta: dict[str, Any] | None, result: "PaginatedResult") -> None:
# send it down the wrong recovery path.
EXIT_TRANSPORT_ERROR: int = 8

# Agent messenger (`dailybot agent connect / ask / replies / webhook`). An agent
# credential is sent as `Authorization: Agent dbagt_…` and only to the messaging doors.
MESSAGING_AGENTS_PATH: str = "/v1/messaging/agents/"
AGENT_TOKEN_SCHEME: str = "Agent"
AGENT_TOKEN_PREFIX: str = "dbagt_"
AGENT_CREDENTIAL_MODE: str = "agent"
MESSENGER_MAX_WAIT_SECS: int = 25 # the server's long-poll ceiling for /replies/
MESSENGER_REPLIES_PAGE_LIMIT: int = 50 # the server's page ceiling for /replies/
# The ask body names the person with this field (participant id `usr_…` or email).
MESSENGER_ASK_PERSON_FIELD: str = "person"


class TransportError(httpx.HTTPError):
"""Raised when a request never produced a readable HTTP response.
Expand Down Expand Up @@ -2631,6 +2642,147 @@ def open_conversation(self, users_uuids: list[str]) -> dict[str, Any]:
)
return self._handle_response(response)

# --- Agent messenger (/v1/messaging/agents/…) ---
#
# `connect` is a person door (the `dailybot login` session as Bearer). Every other
# door here authenticates as the agent itself with `Authorization: Agent dbagt_…`
# and never falls back to another credential: the agent token is the identity.
# Messaging errors use one envelope, `{code, message, detail, retry_after,
# request_id}`, parsed by `_handle_messaging_response`.

def _handle_messaging_response(self, response: httpx.Response) -> dict[str, Any]:
"""Like :meth:`_handle_response`, for the messaging error envelope."""
if response.status_code < 400:
return self._handle_response(response)
code: str | None = None
message: str = _fallback_detail(response)
retry_after: float | None = None
try:
body: Any = response.json()
except Exception:
body = None
if isinstance(body, dict):
raw_code: Any = body.get("code")
if isinstance(raw_code, str):
code = raw_code
raw_message: Any = body.get("message") or body.get("detail")
if isinstance(raw_message, str) and raw_message:
message = raw_message
raw_retry: Any = body.get("retry_after")
if isinstance(raw_retry, (int, float)) and not isinstance(raw_retry, bool):
retry_after = float(raw_retry)
if retry_after is None:
header_retry: str | None = response.headers.get("Retry-After")
if header_retry:
try:
retry_after = float(header_retry)
except ValueError:
retry_after = None
raise APIError(
status_code=response.status_code,
detail=message,
code=code,
retry_after=retry_after,
credential=self._agent_auth_mode,
)

def _agent_credential_request(
self,
method: str,
path: str,
agent_token: str,
*,
json: dict[str, Any] | None = None,
params: dict[str, Any] | None = None,
timeout: float | None = None,
) -> dict[str, Any]:
"""One request as the agent (`Authorization: Agent <token>`), no fallback."""
headers: dict[str, str] = _base_headers()
headers["Authorization"] = f"{AGENT_TOKEN_SCHEME} {agent_token}"
self._agent_auth_mode = AGENT_CREDENTIAL_MODE
kwargs: dict[str, Any] = {
"headers": headers,
"timeout": self.timeout if timeout is None else timeout,
}
if json is not None:
kwargs["json"] = json
if params is not None:
kwargs["params"] = params
response: httpx.Response = self._dispatch_guarded(
method, f"{self.api_url}{MESSAGING_AGENTS_PATH}{path}", **kwargs
)
return self._handle_messaging_response(response)

def messenger_connect(self, name: str, description: str | None = None) -> dict[str, Any]:
"""POST /v1/messaging/agents/connect/ — the signed-in person connects an agent.

Returns ``{"agent": {...}, "credential": {"id", "prefix", "token"}}``; the
token is shown once. The same name reuses the agent and mints a new credential.
"""
payload: dict[str, Any] = {"name": name}
if description:
payload["description"] = description
# A person door: the organization API key is never offered, not even as the
# fallback, so a refusal names the session's real problem.
api_key: str | None = self.api_key
self.api_key = None
try:
response: httpx.Response = self._request(
"POST", f"{self.api_url}{MESSAGING_AGENTS_PATH}connect/", json=payload
)
finally:
self.api_key = api_key
return self._handle_messaging_response(response)

def messenger_me(self, agent_token: str) -> dict[str, Any]:
"""GET /v1/messaging/agents/me/ — the agent behind the credential."""
return self._agent_credential_request("GET", "me/", agent_token)

def messenger_ask(
self,
agent_token: str,
person: str,
text: str,
options: list[str] | None = None,
) -> dict[str, Any]:
"""POST /v1/messaging/agents/me/ask/ — ask one person (email or `usr_…` id)."""
payload: dict[str, Any] = {MESSENGER_ASK_PERSON_FIELD: person, "text": text}
if options:
payload["options"] = list(options)
return self._agent_credential_request("POST", "me/ask/", agent_token, json=payload)

def messenger_replies(
self, agent_token: str, after: str | None = None, wait: int = 0
) -> dict[str, Any]:
"""GET /v1/messaging/agents/me/replies/?after=&wait= — new answers, long-polled.

``wait`` is clamped to the server's 0..25 seconds; the read timeout leaves
room for the whole wait.
"""
bounded: int = max(0, min(int(wait), MESSENGER_MAX_WAIT_SECS))
params: dict[str, Any] = {"wait": bounded, "limit": MESSENGER_REPLIES_PAGE_LIMIT}
if after:
params["after"] = after
return self._agent_credential_request(
"GET",
"me/replies/",
agent_token,
params=params,
timeout=self.timeout + bounded,
)

def messenger_webhook_get(self, agent_token: str) -> dict[str, Any]:
"""GET /v1/messaging/agents/me/webhook/"""
return self._agent_credential_request("GET", "me/webhook/", agent_token)

def messenger_webhook_set(self, agent_token: str, url: str) -> dict[str, Any]:
"""PUT /v1/messaging/agents/me/webhook/ — the answer carries the secret, once."""
return self._agent_credential_request("PUT", "me/webhook/", agent_token, json={"url": url})

def messenger_webhook_delete(self, agent_token: str) -> dict[str, Any]:
"""DELETE /v1/messaging/agents/me/webhook/"""
return self._agent_credential_request("DELETE", "me/webhook/", agent_token)

# --- Agent message endpoints ---

def send_agent_message(
Expand Down
28 changes: 27 additions & 1 deletion dailybot_cli/commands/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

from dailybot_cli import ledger
from dailybot_cli.api_client import APIError, DailyBotClient
from dailybot_cli.commands.agent_messenger import (
agent_ask,
agent_connect,
agent_me,
agent_replies,
webhook_remove,
webhook_set,
webhook_show,
)
from dailybot_cli.commands.public_api_helpers import agent_error_message
from dailybot_cli.config import (
RepoEnvError,
Expand Down Expand Up @@ -746,7 +755,13 @@ def agent_health(

@agent.group(name="webhook")
def agent_webhook() -> None:
"""Manage agent webhooks."""
"""Manage agent webhooks.

\b
set / show / remove the agent messenger webhook (agent credential from
`dailybot agent connect`; signed deliveries of replies)
register / unregister the older agent-message webhook (API key or login)
"""
pass


Expand Down Expand Up @@ -1124,3 +1139,14 @@ def _attempt_register() -> dict[str, Any]:
# Display result
result["profile"] = slug
print_registration_result(result)


# --- Agent messenger (agent credential from `agent connect`) ---

agent.add_command(agent_connect)
agent.add_command(agent_me)
agent.add_command(agent_ask)
agent.add_command(agent_replies)
agent_webhook.add_command(webhook_set)
agent_webhook.add_command(webhook_show)
agent_webhook.add_command(webhook_remove)
Loading
Loading