Skip to content
Open
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ TYPESENSE_API_KEY=your-typesense-api-key-here
# JVSPATIAL_FILES_ROOT_PATH=./.files
# JVSPATIAL_FILE_STORAGE_BASE_URL=http://localhost:8000
# JVSPATIAL_FILE_STORAGE_MAX_SIZE=104857600
# Signed proxy URLs for anonymous media delivery (TTS/WhatsApp). Required when auth is enabled.
# JVSPATIAL_PROXY_ENABLED=true
# JVSPATIAL_PROXY_PREFIX=/p

# S3 (canonical names — do not use *_REGION_NAME / *_ACCESS_KEY_ID / *_SECRET_ACCESS_KEY)
# JVSPATIAL_S3_BUCKET_NAME=
Expand Down
36 changes: 18 additions & 18 deletions .planning/plans/2026-11-06-harness-tracked-assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"path": "examples/jvagent_app/agents/jvagent/leadgen_agent/skills/example_leadgen/SKILL.md",
"scope": "app-example",
"sha256": "sha256:de520833cf56e3e747f2a4ae534cdbf995da6212648c97a0855cf829d1497128",
"sha256": "sha256:b8a19a4eaad41c64317d9d86f2be48cdd850c4f10f227530b052f0c0643c04c8",
"name": "example_leadgen",
"spec": null,
"extends": "action:jvagent/leadgen",
Expand Down Expand Up @@ -94,7 +94,7 @@
{
"path": "examples/jvagent_app/agents/jvagent/leadgen_agent/skills/product_inquiry_leads/SKILL.md",
"scope": "app-example",
"sha256": "sha256:e342e973c6ce9fd6ce2d0430adac37da8dba85138db6d7b552d8389a9c64d060",
"sha256": "sha256:0603c34934fc834d456c42bc4b4a8bdc855b058d18f5296c9db80b705c588f65",
"name": "product_inquiry_leads",
"spec": null,
"extends": "action:jvagent/leadgen",
Expand Down Expand Up @@ -513,7 +513,7 @@
{
"path": "jvagent/action/leadgen/SKILL.md",
"scope": "package",
"sha256": "sha256:02e3de03fbdf06772cddb2ebf5290d7c09ba6f60de0b6997c5362690386cf6cd",
"sha256": "sha256:4a34f16549137f67b758678e2c2017a63469872be9b8e2a4526e328585d601da",
"name": "leadgen_base",
"spec": null,
"extends": null,
Expand All @@ -533,12 +533,12 @@
"name"
],
"tracked_directory_files": 20,
"tracked_directory_digest": "sha256:1a6be2ca8095118e4a399620db144ee69aee850d362076f215effad8e5b3d19e"
"tracked_directory_digest": "sha256:75f03f9262a664af9368abaf16923cf354607c5086f5f2d4ceefd4d0c0e00667"
},
{
"path": "jvagent/action/leadgen/examples/example_leadgen/SKILL.md",
"scope": "package",
"sha256": "sha256:019976d27a37192f030568a838d61931c83a8e5a8e502b35ac2752c71cd261c3",
"sha256": "sha256:e0410e232030480d882fa87b1f5fd96c066c4cb0f79f15b6ada4a9f5196baf63",
"name": "example_leadgen",
"spec": null,
"extends": "action:jvagent/leadgen",
Expand Down Expand Up @@ -1291,7 +1291,7 @@
"name": "jvagent/handoff_action",
"archetype": "HandoffAction",
"tracked_directory_files": 4,
"tracked_directory_digest": "sha256:5f8d9c9a8c9b5b7cac0cafa61eff1edcb4f618f960126708e6463daadf78deaa"
"tracked_directory_digest": "sha256:0514274e3bc852c9b17d03de09adb00c0fcef0c461b29c5f173b3227c2d92050"
},
{
"path": "jvagent/action/interview/info.yaml",
Expand All @@ -1309,7 +1309,7 @@
"name": "jvagent/intro_interact_action",
"archetype": "IntroInteractAction",
"tracked_directory_files": 3,
"tracked_directory_digest": "sha256:1f53c59c6e160931fbe0aac2e8302077800dc3b388939b7cc42288c4613fade2"
"tracked_directory_digest": "sha256:750df6352ea0626c8583342d38b2fffa98a598731ddbac6986356edcedea5aee"
},
{
"path": "jvagent/action/leadgen/info.yaml",
Expand All @@ -1318,25 +1318,25 @@
"name": "jvagent/leadgen",
"archetype": "LeadGenAction",
"tracked_directory_files": 20,
"tracked_directory_digest": "sha256:1e7d64246b31b1775e2f4694a0d129aa282d6fa656a5f14f88271653088242a4"
"tracked_directory_digest": "sha256:3d973e40af17d1413500dd8d38a461b402f53aa9c41cb773c276eec3cb4ec086"
},
{
"path": "jvagent/action/mcp/info.yaml",
"scope": "package",
"sha256": "sha256:556282e31e4399046a4d081db544a51a5012f7437e0d3a087c7b08473037def0",
"name": "jvagent/mcp",
"archetype": "MCPAction",
"tracked_directory_files": 8,
"tracked_directory_digest": "sha256:8a1cbe7486e365c139c2400c1a995cca2b7c4f820baa79d514050b74f118f039"
"tracked_directory_files": 11,
"tracked_directory_digest": "sha256:c54bb47f607f69572fdeb0bc23755e7eb391920c0c94af1181fc3038c20767c6"
},
{
"path": "jvagent/action/mcp_oauth/info.yaml",
"scope": "package",
"sha256": "sha256:c7e662950af0eedd604ed2d4f6c5f508e7d8d14a1245f6f2ed0e0bbcb50c455f",
"name": "jvagent/mcp_oauth",
"archetype": "MCPOAuthAction",
"tracked_directory_files": 8,
"tracked_directory_digest": "sha256:5071e9a1657a37d9330af66bbb2c754d070ce9e669e4507e6f89b8b5f093bade"
"tracked_directory_files": 9,
"tracked_directory_digest": "sha256:79805a8c9b64fae3ffe3651fb491b406b24a0c5fb262c7f3c5c4a52604778b47"
},
{
"path": "jvagent/action/microsoft/microsoft_excel_action/info.yaml",
Expand Down Expand Up @@ -1489,7 +1489,7 @@
"name": "jvagent/orchestrator",
"archetype": "OrchestratorInteractAction",
"tracked_directory_files": 32,
"tracked_directory_digest": "sha256:3a09e66b9885fd063026b799ee38a977a8af36ff862c75b9ed794bab90dfc215"
"tracked_directory_digest": "sha256:729f3b3bb16e88c37d18e2b052be25533f1071b74f5f53d9631bb5fc940e4a93"
},
{
"path": "jvagent/action/page_context/info.yaml",
Expand All @@ -1516,7 +1516,7 @@
"name": "jvagent/pageindex_google_drive_sync_action",
"archetype": "PageIndexGoogleDriveSyncAction",
"tracked_directory_files": 7,
"tracked_directory_digest": "sha256:314daafbdb6059d9f3230bf3555084310f6d16012d0063eb7d54fd63c5e678a6"
"tracked_directory_digest": "sha256:b3fee5529d8ef16a9ef5d271cb4fab753cc25a2ab8779e3d86ce69eafa7ce79f"
},
{
"path": "jvagent/action/pageindex_read/info.yaml",
Expand All @@ -1543,7 +1543,7 @@
"name": "jvagent/reply",
"archetype": "ReplyAction",
"tracked_directory_files": 3,
"tracked_directory_digest": "sha256:4efe3cc77e7614415192293d6d66f2a1a7bb610eb05f0890c21bb8db7c957f34"
"tracked_directory_digest": "sha256:494b814f4c0a795c01fb999935414e7fb299bb4ffd7ae591dd3b07ff7fff5dbe"
},
{
"path": "jvagent/action/sentdm_broadcast/info.yaml",
Expand Down Expand Up @@ -1615,7 +1615,7 @@
"name": "jvagent/elevenlabs_tts",
"archetype": "ElevenLabsTTSAction",
"tracked_directory_files": 2,
"tracked_directory_digest": "sha256:0486050f24c4817cc8ed221ff8a0c3e70e31641e69f5b52a96cc037a0140ca6f"
"tracked_directory_digest": "sha256:affa7b96fc536e44da4fb8aae8a5d60c9ac7c91d3b7689c1006eabb573804a77"
},
{
"path": "jvagent/action/ui/info.yaml",
Expand Down Expand Up @@ -1696,7 +1696,7 @@
"name": "jvagent/whatsapp_action",
"archetype": "WhatsAppAction",
"tracked_directory_files": 29,
"tracked_directory_digest": "sha256:91b3f52eb6e45de0df83d18ba3eb6629aa8da34913d1f4606edcb2b4bf2393e2"
"tracked_directory_digest": "sha256:d107c5381d332ee31097cc187e74f104162cb1edf510370b97d4f8117b6e49c0"
},
{
"path": "jvagent/action/whatsapp_voice/info.yaml",
Expand Down Expand Up @@ -1756,7 +1756,7 @@
}
],
"tracked_directory_files": 11,
"tracked_directory_digest": "sha256:89ad2c0a2b659fce3b43117200f6c6471b803d6519d5f146bdd440caf80bbcbe"
"tracked_directory_digest": "sha256:e5ad944ce4b0fea366233fbe1dbf6767fa9a90c3c10bd3e9a8410252a67eeb68"
},
{
"path": "examples/jvagent_app/agents/jvagent/orchestrator_agent/agent.yaml",
Expand Down
3 changes: 2 additions & 1 deletion .planning/reference/configuration-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ See [`docs/ORCHESTRATOR.md`](../../docs/ORCHESTRATOR.md) for the full pattern. H
| `grounding_max_deflections` | `2` | how many times a turn may be deflected for an unsupported source claim or an invented specific before the reply passes; `0` disables. The corpus a reply is checked against is the user message, history, this turn's tool results and the SESSION CONTEXT block, so a year or date read from the clock is grounded |
| `repeat_guard_window` | `8` | how many recent tool calls the repeat guard remembers; a call repeating one in the window (same tool + args) is nudged once and ends the turn on the second repeat; a repeat after an error/timeout gets one retry |
| `history_limit` | `4` | prior turns fed into the loop prompt (working context). The rolling memory window is the agent-level `interaction_limit`. Loop history omits `[EVENT]` lines unless `with_event` is on (ADR-0041, amended by ADR-0053) |
| `with_event` | `false` | include `[EVENT]` lines from PRIOR interactions in loop history — log annotations about what the agent did out of band ("Report form was sent to the user"). Off = today's prompt, byte for byte. The current interaction is always excluded from its own history (ADR-0053) |
| `with_event` | `false` | include `[EVENT]` lines from PRIOR interactions in loop history — log annotations about what the agent did out of band ("Report form was sent to the user"). Off = today's prompt, byte for byte. The current interaction is always excluded from its own history (ADR-0053). When on, `hide_correlation` (default true) omits harness correlation events |
| `hide_correlation` | `true` | when `with_event` is on, omit harness correlation `[EVENT]` lines (`action_name=harness` / `corr-*`). Default keeps product side-effect events while omitting turn correlation noise. Set `false` to include correlation. Ignored when `with_event` is false |
| `history_statement_max_chars` | `4000` | per-statement cap on each replayed prior utterance/response, and on each `[EVENT]` line when `with_event` is on (history is resent every tick). `0` disables |
| `lock_active_flow` | `true` | deterministic turn-lock to an active flow's IA; `false` = model-mediated continuation (ADR-0013) |
| `planning` | `false` | surface the `update_plan` tool so the model records a multi-step plan that persists across turns (`AGENTIC_LOOP` task on the `TaskStore`) and resumes an interrupted turn; off = zero cost (ADR-0019) |
Expand Down
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,46 @@ and this project adheres to [PEP 440](https://peps.python.org/pep-0440/) /

## [Unreleased]

### Changed

- **`IntroInteractAction` publishes dual-scope intro parameters.** On
`visitor.new_user` it now adds `intro.first_message` at both
`orchestration` and `response` scope with the configured `directive` text, so
the executive that authors the reply sees the custom intro (not only
ReplyAction compose). Agents should put the full intro in
`intro_interact_action.directive` and not duplicate it into
`orchestrator.system_prompt_extra`.

- **Leadgen is LLM-driven.** Removed `ask_next` and the `pending_activation` guard;
capture/retrieve results now include `optional_fields` (the optional pool with
guidance) and `validation_errors`; the base procedure is generic (required first,
optional by guidance, content-first extraction, one question); validation is per
field and keeps valid values; declines bypass validators. Breaking for callers that
passed `ask_next`.

- **Leadgen base procedure hardened.** A withheld value ("no organization",
"none", "n/a", "personal", "not provided") is captured as that field's
`decline_value` instead of the visitor's phrase; every value the message
supplies is captured in that same turn before any field question; and a `skipped`
(including sync thresholds not met), `no-op`, or `failed` sync is a hand-off that
has not run, so the reply says the request is saved but not yet sent instead of
closing on an acknowledgement. The open optional pool is capped at five keys
(`MAX_OPTIONAL_FIELDS`) so the directive stays a bounded menu. The optional ask
now names the need criterion ("the one this request needs") instead of a
permission, and the hand-off sentence is not repeated on later captures
(`_leadgen_handoff_stated`, reset when a snapshotted field changes).
`gap_fill.priority`, `qualification`, and `project_qualification` are accepted
and ignored. The failed-hand-off reply names `sync.sales_contact` (or the
action's `sales_contact`) only when one is configured.

### Fixed

- **TTS media URLs work with authentication enabled.** `as_url=True` now returns
a signed proxy URL (`/p/{code}`) instead of the auth-protected
`/api/files/...` route, so WhatsApp/Messenger adapters and LLM providers can
fetch voice notes anonymously. Requires `JVSPATIAL_PROXY_ENABLED=true`; the
action logs a warning and falls back to the direct file route when proxy URLs
are unavailable.
- **Handoff mode prompts corrected.** The consult/transfer trigger is now gated
on the owning skill/tool having run ("after the owning skill or tool ran, the
answer is not in this turn's tool results"), so it cannot fire before the first
Expand Down
5 changes: 4 additions & 1 deletion docs/ORCHESTRATOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ Interaction `[EVENT]` lines are omitted from loop history by default
(ADR-0041) — they cost ~100+ tokens/tick when resent. Set `with_event: true`
when the loop must know what the agent did out of band in earlier turns
(ADR-0053); each line is then capped by `history_statement_max_chars` like any
other replayed statement. Bench a realistic turn with `--history N`.
other replayed statement. Harness correlation events (`action_name=harness` /
`corr-*`) stay out by default via `hide_correlation: true`; set
`hide_correlation: false` to include them. Bench a realistic turn with
`--history N`.

**4. Cache accounting.** OpenAI caches long prefixes automatically and reports
hits in `usage.prompt_tokens_details.cached_tokens`; Anthropic caches only up to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ leadgen:
guidance: Brief description of their project or need
gap_fill:
batch: true
priority: [name, phone, email, organization]
sync:
mode: on_capture
min_fields: [name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ leadgen:
merge: true
gap_fill:
batch: true
priority: [name, phone, email, organization]
# Sync config (mode, thresholds, destinations) lives in agent.yaml on the
# jvagent/leadgen action — it's deployment/infra, not skill semantics. The
# skill defines WHAT to capture; the agent defines WHERE it syncs.
Expand Down
112 changes: 92 additions & 20 deletions jvagent/action/google/google_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,54 @@
_OIDC_SCOPES = frozenset({"openid", "profile", "email"})


class GoogleAuthRequiredError(ValueError):
"""An MCP OAuth credential exists but cannot be used for this Google API.

Callers distinguish the three states that used to share one opaque
``ValueError`` message: no credential at all, a credential whose granted
scopes cannot serve this action, and a refresh Google rejected.
"""

def __init__(
self,
message: str,
service: str = "",
auth_url: str = "",
reason: str = "not_connected",
missing_scopes: Optional[List[str]] = None,
) -> None:
# Every argument goes to BaseException.args so pickle and copy.copy
# can rebuild the instance. str() stays the human message.
scopes = list(missing_scopes or [])
super().__init__(message, service, auth_url, reason, scopes)
self.service = service
self.auth_url = auth_url
self.reason = reason
self.missing_scopes = scopes

def __str__(self) -> str:
return str(self.args[0]) if self.args else ""


def _granted_scopes(token_data: Optional[Dict[str, Any]]) -> List[str]:
"""Raw granted scopes from a stored token blob (string or list form)."""
raw = (token_data or {}).get("scopes")
if isinstance(raw, str) and raw.strip():
return raw.split()
if isinstance(raw, list):
return [str(s).strip() for s in raw if str(s).strip()]
return []


def _api_scopes(granted: List[str]) -> List[str]:
"""Granted scopes that map to a Google API call (drops OIDC scopes)."""
return [
s
for s in granted
if s.startswith("https://www.googleapis.com/auth/") and s not in _OIDC_SCOPES
]


def _normalize_expiry(value: Any) -> Optional[str]:
"""Coerce a stored expiry into the naive-UTC ISO form google-auth parses.

Expand Down Expand Up @@ -190,24 +238,13 @@ async def _load_mcp_token(

def _scopes_for_refresh(self, token_data: Optional[Dict[str, Any]]) -> List[str]:
"""This action's granted API scopes only (no OIDC / extra APIs)."""
raw = (token_data or {}).get("scopes")
granted: List[str] = []
if isinstance(raw, str) and raw.strip():
granted = raw.split()
elif isinstance(raw, list):
granted = [str(s).strip() for s in raw if str(s).strip()]
if not granted:
api = _api_scopes(_granted_scopes(token_data))
if not api:
return []
api = {
s
for s in granted
if s.startswith("https://www.googleapis.com/auth/")
and s not in _OIDC_SCOPES
}
wanted = [s for s in (self.SCOPES or []) if s]
if wanted:
return [s for s in wanted if s in api]
return [s for s in granted if s in api]
return api

def _credentials_from_mcp_payload(self, token_data: Dict[str, Any]) -> Any:
env_secret = self._resolve_client_secret_from_env()
Expand All @@ -231,9 +268,13 @@ async def _get_credentials(self) -> Any:
account_name, token_data, _node = await self._load_mcp_token()
label = self.__class__.__name__
auth = self._mcp_auth_url()
service = self._MCP_SERVICE or ""
if not token_data or not token_data.get("refresh_token"):
raise ValueError(
f"No valid MCP OAuth credentials for {label}. Authorize at {auth}"
raise GoogleAuthRequiredError(
f"Google credential for {label} is not connected. Authorize at {auth}",
service=service,
auth_url=auth,
reason="not_connected",
)

refresh_scopes = self._scopes_for_refresh(token_data)
Expand Down Expand Up @@ -264,15 +305,46 @@ async def _get_credentials(self) -> Any:
client_id_hint=getattr(creds, "client_id", None),
extra_details={"error_type": type(e).__name__},
)
raise ValueError(
raise GoogleAuthRequiredError(
f"OAuth2 credentials for {label} expired and could not "
f"be refreshed. Re-authorize at {auth}"
f"be refreshed. Re-authorize at {auth}",
service=service,
auth_url=auth,
reason="refresh_failed",
) from e
return creds
raise ValueError(
f"No valid MCP OAuth credentials for {label}. Authorize at {auth}"

# Expired (or unusable) with nothing safe to refresh with. When the
# stored grant is the cause, say which scope is missing: a partial
# consent still produces a refresh token, so "not authorized" alone
# sends the operator looking in the wrong place.
api = _api_scopes(_granted_scopes(token_data))
missing = [s for s in (self.SCOPES or []) if s and s not in api]
if missing:
raise GoogleAuthRequiredError(
f"Google credential for {label} is missing required scope(s): "
f"{', '.join(missing)}. Re-authorize at {auth} and keep the "
"matching permission checked.",
service=service,
auth_url=auth,
reason="missing_scope",
missing_scopes=missing,
)
raise GoogleAuthRequiredError(
f"No valid MCP OAuth credentials for {label}. Authorize at {auth}",
service=service,
auth_url=auth,
reason="not_connected",
)

async def assert_authorized(self) -> Any:
"""Return usable credentials or raise ``GoogleAuthRequiredError``.

Callers that must not start work on an unusable credential use this
instead of catching a generic error from ``get_service``.
"""
return await self._get_credentials()

async def _load_credentials(self) -> Any:
"""Alias for Docs and other callers that still use this name."""
return await self._get_credentials()
Expand Down
Loading
Loading