Bindu icon indicating copy to clipboard operation
Bindu copied to clipboard

feat: add stateful joke agent example with retry logic, memory and observability

Open KartikL1 opened this issue 9 months ago • 5 comments

🚀 Describe your changes clearly

Added a new example agent: examples/joke_agent/joke_agent.py

This is a stateful joke agent that demonstrates real engineering patterns within the Bindu framework, going beyond a basic echo agent to show how production-quality agents should be built.

Category detection Detects joke category from natural language input (tech, dad, dark, general) using keyword matching. No LLM or API key required.

Retry with exponential backoff + jitter Fetches jokes from a public API with up to 3 retry attempts. Each retry waits (2^attempt) + random(0,1) seconds — exponential backoff with jitter to prevent the thundering herd problem.

Memory system Uses deque(maxlen=5) to track recently told jokes and avoid repetition. Resets automatically when all category jokes are seen.

Observability Structured logging on every request showing category, source (api/local), and running stats (total_served, api_hits, fallback_hits, by_category).

Graceful fallback If all API retries fail, agent falls back to a curated local joke dataset. Agent never returns an error to the user.

Files changed

  • examples/joke_agent/joke_agent.py — the agent
  • examples/joke_agent/README.md — setup and usage docs
  • tests/unit/test_joke_agent.py — 17 unit tests, all passing

Tests pytest tests/ -q --ignore=tests/unit/test_did_extension.py

552 passed, 78 warnings (includes 17 new tests)

All 17 new tests cover: category detection, local joke fetching, memory/no-repeat logic, stats tracking, handler response format, API retry success, and API failure fallback.

How I approached this Before writing any code I read bindufy.py, studied existing examples using ls examples/, checked test_retry.py to understand patterns already in the codebase, and verified the existing test suite passed. Noticed weather-research/ already existed so built something original. Added if __name__ == '__main__' guard after realising pytest would otherwise start the full server on import — this was a key debugging insight.

Note on local testing environment Development was done on Windows. The ed25519-blake2b dependency requires Microsoft C++ Build Tools on Windows, which prevented running the complete Bindu server locally. However all agent logic is fully tested via 17 unit tests that pass successfully. The x402/payments module is not used by this agent. The code runs without issues on Linux/macOS.

Related roadmap items This example demonstrates retry mechanism patterns applied at the agent level, and shows how the bindufy() decorator works in a realistic, production-quality use case beyond a basic echo agent.

✅ Checklist clearly

  • [x] I've tested my changes thoroughly.
  • [x] I've followed the project's style and linting rules.
  • [x] I've updated documentation (if required).

📌 Related issue clearly

No related issue. This is a new example agent contribution demonstrating the bindufy() pattern with production-quality engineering practices.

KartikL1 avatar Feb 16 '26 14:02 KartikL1

Hi @Paraschamoli

Thanks for the review. Could you help me understand why it was marked duplicate/invalid? I couldn't find an existing joke agent in the examples folder when I checked before building.

If this contribution doesn't fit, I'd love to pivot to something more useful. I'm looking at increasing test coverage to 80% (currently on the roadmap) , Would that be a better direction?

Happy to put in the work wherever it's needed most!

KartikL1 avatar Feb 17 '26 13:02 KartikL1

joke agent is already present in examples

Paraschamoli avatar Feb 17 '26 14:02 Paraschamoli

Thanks for clarifying @Paraschamoli!

I checked the examples folder before building and saw weather-research but missed an existing joke agent. My mistake.

I'll pivot to something more useful, planning to work on increasing test coverage to 80% as mentioned in the roadmap. Will open a new PR shortly!

KartikL1 avatar Feb 17 '26 14:02 KartikL1

https://github.com/GetBindu/Bindu/blob/main/examples/beginner/agno_example.py

Paraschamoli avatar Feb 17 '26 14:02 Paraschamoli

Thanks for sharing @Paraschamoli! I went through the agno_example yesterday only.

I've pivoted to something more useful for the project , working on increasing test coverage for bindu/utils/http_client.py (currently at 38% coverage). Just wrote 28 unit tests covering all HTTP methods, retry logic with exponential backoff, session management, and the context manager helper. Overall coverage increased from 65.17% → 65.77%.

Planning to open PR #2 shortly. Is there a specific coverage target or priority files you'd like contributors to focus on?

KartikL1 avatar Feb 19 '26 15:02 KartikL1