Skip to content

feat(tools): add knowledge base search example#81

Open
xinghaohuang91 wants to merge 3 commits into
mainfrom
feat/knowledge-tool-example
Open

feat(tools): add knowledge base search example#81
xinghaohuang91 wants to merge 3 commits into
mainfrom
feat/knowledge-tool-example

Conversation

@xinghaohuang91

@xinghaohuang91 xinghaohuang91 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a runnable knowledge base search example and fixes serialization bugs in the OpenAI Agents SDK tool bridge.

  • New example getting_started/examples/features/knowledge.py — an LLM agent that answers user questions by searching a Twilio Knowledge Base via create_knowledge_tool. Modeled on the existing handoff.py.
  • Bug fix TACTool.to_openai_agents_sdk_tool() now JSON-serializes Pydantic tool results. The built-in knowledge tool returns list[KnowledgeChunkResult], which the stdlib json.dumps couldn't encode — any tool returning Pydantic models crashed with Object of type ... is not JSON serializable.
  • Bug fix the same path now uses model_dump(mode="json") so models with non-primitive fields (datetime, UUID, Decimal) coerce to JSON-encodable values instead of crashing at json.dumps. Covered by a new test.
  • Observability — added a debug log on tool invocation so tool calls are visible in logs.
  • Docs: added the example + TWILIO_KNOWLEDGE_BASE_ID to getting_started/README.md and .env.example.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Release / version bump

Checklist

  • Tests added/updated
  • Documentation updated
  • Tested E2E

SDK Parity

The serialization fixes affect shared tool functionality and should be mirrored in the TypeScript SDK.

  • Change is Python-specific (no TypeScript update needed)
  • TypeScript SDK PR created:

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 9, 2026 22:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@xinghaohuang91
xinghaohuang91 requested a review from Copilot July 9, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment thread src/tac/tools/base.py
Comment thread src/tac/tools/base.py Outdated
Comment thread getting_started/examples/features/knowledge.py
Comment thread getting_started/examples/features/knowledge.py
Comment thread getting_started/examples/features/knowledge.py
Comment thread getting_started/examples/features/knowledge.py
Comment thread getting_started/examples/features/knowledge.py
Feature: Knowledge Base Search Tool

Demonstrates TAC's knowledge tool letting an LLM agent answer questions by
searching a Twilio Knowledge Base. Works on voice and SMS.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove Works on voice and SMS.

makes it sound like knowledge only works on voice and sms instead of all channels

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment thread getting_started/README.md Outdated
@@ -128,6 +130,7 @@ See `examples/.env.example` for all available configuration options. Key variabl

### Optional (Channel-Specific)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove (Channel-Specific) here now? Since the vars are not specific.

maybe (channel and feature specific) instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense.

Comment thread src/tac/tools/base.py
"Install with: pip install openai-agents"
) from e

def _json_default(obj: object) -> object:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Add getting_started knowledge tool example (voice + SMS). Fix Agents
SDK bridge to JSON-serialize Pydantic tool results (knowledge tool
returned list[KnowledgeChunkResult], which crashed json.dumps), and
add a debug log on tool invocation.
Use model_dump(mode="json") so Pydantic models returned by tools (e.g.
knowledge base chunks) coerce non-primitive fields to JSON-encodable
values before json.dumps.
- Drop 'Works on voice and SMS' from knowledge example docstring
- Rename README env section from 'Optional (Channel-Specific)' to 'Optional'
@xinghaohuang91
xinghaohuang91 force-pushed the feat/knowledge-tool-example branch from 39dcf28 to e5846ff Compare July 14, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants