Skip to content

feat: unblock agent workflow — pager-free help + subtype narrowing#61

Merged
prantogg merged 2 commits intomainfrom
pranav/feature/agent-ux
Apr 27, 2026
Merged

feat: unblock agent workflow — pager-free help + subtype narrowing#61
prantogg merged 2 commits intomainfrom
pranav/feature/agent-ux

Conversation

@prantogg
Copy link
Copy Markdown
Member

@prantogg prantogg commented Apr 24, 2026

Why

From an agent session (Copilot, terminal shell, local install):

pip show wkls OR python3 -c "import wkls; help(wkls)" | head -50
# … pager hangs, agent sends 'q', then echo 'test', finally:
PAGER=cat MANPAGER=cat python3 -c "..."

Agent wasted ~8 commands escaping the terminal pager that help(wkls) opens. Then spent another ~10 commands on inspect.signature + dir(Wkl) to reverse-engineer the API. Finally ran .search('san diego').wkt(), hit AmbiguousLocationError, and jumped to by_id('<uuid>') from the error message — never discovering that .search('san diego').cities().wkt() is a faster path.

What

Three changes unblock the agent workflow without rewriting anything:

  1. wkls.help() — prints the module docstring to stdout. Same content as help(wkls) but no pager. Listed in dir(wkls) so agents find it. Intentionally omitted from __all__ to avoid polluting from wkls import *.
  2. AmbiguousLocationError suggests subtype narrowers when candidates span multiple subtypes. E.g. for San Diego (city + county), the error now emits .cities() / .counties() alongside by_id(...). Suppressed when narrowing wouldn't reduce the set (e.g. all 18 Franklin townships in PA are localities — .cities() wouldn't help, so it isn't suggested).
  3. Multi-row result-mode dir() advertises the listing methods (cities, counties, regions, countries, dependencies, subtypes). Previously only inspection verbs (count, head, etc.) showed up — so agents never saw the subtype-filter path unless they read the docstring.

Module docstring updated to lead with wkls.help() and list subtype narrowing as option (a) under "Resolving ambiguity".

Also includes a small unrelated build fix: broader .venv-* ignore + explicit hatch sdist excludes so uv build doesn't pick up local virtualenvs or test_nb.ipynb.

Test plan

  • uv run pytest — 151 passed, 2 xfailed (added 3 tests: pager-free help, subtype suggestion fires, subtype suggestion suppressed when redundant)
  • Smoke-tested the suggested narrower end-to-end: wkls.us.ca.search('san diego').cities().wkt() returns a valid WKT
  • dir(wkls) includes help; dir(wkls.us.ca.search('san diego')) includes cities, counties, etc.
  • uv build succeeds with a 35-file sdist (no .venv-* / notebooks)

Follow-ups (not in this PR)

Scoped out to keep this PR focused on the agent-trap we set out to fix. Tracked from a Copilot usability review + an ecosystem survey in docs/investigations/llm-friendly-library-patterns.md:

  • .head(n) / .limit(n) should return a Wkl, not a raw sedona DataFrame. Agents naturally chain .head(3).to_dicts() and it fails because .to_dicts() is a Wkl method, not a DataFrame method. Fix is ~10 LOC — wrap the sliced DataFrame in a result-mode Wkl.
  • Did you mean '<X>'? on unknown chain attributes. wkls.us.ca.sanfransisco should suggest sanfrancisco via difflib.get_close_matches. Python 3.10+ ships this for NameError/AttributeError; we'd mirror that convention for chain misses. ~20 LOC.
  • Distinguishing labels for identical-looking ambiguity candidates. Two Yorks in York County, PA currently render as two identical lines in the error — append last-4-of-UUID (or similar) so visually distinct, even if the ultimate picker is still by_id.
  • Ship docs/llms.txt — short index file following the Answer.AI convention (adopted by Pydantic AI, Anthropic docs, Stripe, Cloudflare). Pointers to README + per-feature markdown sections, not inline docs. Near-zero maintenance.

…wing

Agents running `python -c "import wkls; help(wkls)"` get stuck on
the terminal pager. Three changes unblock that workflow:

1. wkls.help() prints the guide without touching the pager — same
   content as the module docstring, just via print(). Surfaced in
   dir(wkls) so agents discover it via introspection. Omitted from
   __all__ to avoid polluting 'from wkls import *'.

2. When an AmbiguousLocationError spans multiple subtypes (e.g.
   .search('san diego') returns both the city and the county), the
   error now suggests .cities() / .counties() alongside by_id(). The
   narrower is the method, not the subtype attribute — dot access is
   still admin-hierarchy only.

3. Multi-row result-mode Wkl's dir() advertises the listing methods
   (cities, counties, regions, countries, dependencies, subtypes) so
   the subtype-filter path shows up in auto-complete / introspection,
   not just in docs.

Module docstring updated to lead with wkls.help() and list subtype
narrowing as option (a) in the ambiguity section.
@prantogg prantogg force-pushed the pranav/feature/agent-ux branch from 26607cc to 5e0ed70 Compare April 24, 2026 16:55
`uv build` was packaging the working directory's `.venv-1.0.1/` into
the source distribution because .gitignore's `.venv` pattern only
matched the exact name, not suffixed variants. That tripped the
sdist unpack step on restricted files inside jedi's bundled typeshed.

Broaden the ignore pattern to `.venv-*` and add explicit hatch sdist
excludes as a belt-and-suspenders guard for any non-VCS packaging
path — plus the untracked `test_nb.ipynb` and `docs/` that shouldn't
ship in wheels either.
@prantogg prantogg marked this pull request as ready for review April 27, 2026 19:04
@prantogg prantogg merged commit 5d713a1 into main Apr 27, 2026
7 checks passed
@prantogg prantogg deleted the pranav/feature/agent-ux branch April 27, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant