Skip to content

DOC-1892: Fix Semantic Kernel notebook for semantic-kernel 1.x - #50

Closed
snova-gilvanm wants to merge 1 commit into
sambanova:mainfrom
snova-gilvanm:DOC-1892-semantic-kernel-notebook
Closed

DOC-1892: Fix Semantic Kernel notebook for semantic-kernel 1.x#50
snova-gilvanm wants to merge 1 commit into
sambanova:mainfrom
snova-gilvanm:DOC-1892-semantic-kernel-notebook

Conversation

@snova-gilvanm

Copy link
Copy Markdown
Collaborator

Summary

The Semantic Kernel example notebook does not run. It fails on the first line of main() with:

TypeError: ChatCompletionAgent.__init__() got an unexpected keyword argument 'service_id'

This is the sambanova/integrations half of DOC-1892. The docs half is sambanova/docs#984.

The notebook appears to have been committed without ever completing a run — cells 2-4 carried execution counts 3/4/5 while the imports cell and await main() had none and no outputs.

Blocking fixes

1. service_id removed from ChatCompletionAgent

Removed in semantic-kernel 1.0; the agent takes a configured kernel instead. Matches the current upstream sample, step06_chat_completion_agent_group_chat.py. OpenAIChatCompletion still accepts service_id, so _create_kernel_with_chat_completion is unchanged.

2. metadata.kernelspec was semantic_kernel_venv

A machine-local kernel name. Anyone else opening the notebook gets:

jupyter_client.kernelspec.NoSuchKernel: No such kernel named semantic_kernel_venv

Now python3, which any ipykernel install provides.

Correctness

  • Restored the "not approved" guard in ApprovalTerminationStrategy. The check was "approved" in history[-1].content.lower(), so a reviewer replying "this is not approved" terminated the chat as if it had passed. Also guards a None content.
  • Subclass TerminationStrategy rather than DefaultTerminationStrategy, matching upstream.

Dependencies

  • Added python-dotenv. The notebook does from dotenv import load_dotenv, but nothing declared it — it resolved only transitively via semantic-kernelpydantic-settings.
  • Bounded semantic-kernel>=1.44,<2. On Python 3.9, pip does not error; it backsolves to 0.9.6b1 (2024) which fails with ImportError: cannot import name 'Url' from 'pydantic.networks' — a traceback that names pydantic and never mentions the Python version. The floor turns that silent downgrade into a resolver error.

Housekeeping

  • Fixed the logo anchor: stray backslash in <a href="..."\> and crossed <a>/<picture> nesting.
  • Fixed the dead upstream link (step3_chat.py → 404) and a levaraging typo.
  • Removed the unused asyncio import and sys.path.append('../../'); cleared stale execution counts and outputs.

Verification

Fresh Python 3.11 venv built only from the updated requirements.txt, then nbconvert --execute with no override flags:

EXIT CODE: 0
ERROR CELLS: 0
exec counts: [1, 2, 3, 4, 5]
# Agent - CopyWriter: '"Charge Ahead" - simple, direct, ...'
# Agent - ArtDirector: '... Approved, but with room for refinement.'
# IS COMPLETE: True

Notes for reviewers

  • Opened from a fork — I have read-only access to this repo.
  • The approval heuristic is still substring-based and terminates on "Approved, but with room for refinement", as the run above shows. Upstream has the same weakness, so I matched it rather than diverging. Happy to harden it if preferred.
  • AgentGroupChat is deprecated upstream in favour of GroupChatOrchestration. Migrating the sample is a larger change and out of scope here.
  • Eight other notebooks in this repo carry the same machine-local kernelspec defect (agentops_venv, autogen_venv, instructor_venv, venv, haystack_test, langgraph_env, base_env, petro_test_2). Worth a sweep in a separate ticket.

🤖 Generated with Claude Code

The notebook was committed without ever having been run end to end: cells
2-4 carried execution counts while the imports cell and `await main()` had
none. It fails on the first line of `main()`.

Blocking fixes:
- Drop the `service_id` argument from `ChatCompletionAgent`. It was removed
  in semantic-kernel 1.0, which raises TypeError. The agent takes a
  configured `kernel` instead. `OpenAIChatCompletion` still accepts it.
- Set `metadata.kernelspec` to `python3` instead of `semantic_kernel_venv`,
  a machine-local kernel name that raises NoSuchKernel for everyone else.

Correctness:
- Restore the `"not approved"` guard in ApprovalTerminationStrategy. Without
  it, a reviewer reply of "this is not approved" terminated the chat as if
  it had passed. Guard against a None `content` while here.
- Subclass TerminationStrategy rather than DefaultTerminationStrategy, to
  match the upstream sample.

Dependencies:
- Declare `python-dotenv`, which the notebook imports but nothing declared;
  it resolved only transitively via semantic-kernel -> pydantic-settings.
- Bound `semantic-kernel>=1.44,<2`. On Python 3.9 pip silently backsolves to
  0.9.6b1, which fails with an unrelated-looking ImportError from pydantic.

Housekeeping:
- Fix the malformed logo anchor (stray backslash, crossed <a>/<picture>
  nesting), the dead upstream link, and a typo.
- Remove the unused `asyncio` import and `sys.path` append; clear stale
  execution counts.

Verified with a fresh Python 3.11 venv built from requirements.txt:
nbconvert --execute exits 0 with no error cells and both agents respond.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@snova-gilvanm

Copy link
Copy Markdown
Collaborator Author

Closing this cross-repo PR. Reopening from a branch on the official repo now that I have admin access.

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.

2 participants