microsoft/semantic-kernel · error · AgentInitializationException

'count' must be an integer in: {spec}

Error message

'count' must be an integer in: {spec}

What it means

Raised when a bing_grounding tool spec's count option is present but not a Python int. count controls how many Bing search results the grounding tool considers.

Source

Thrown at python/semantic_kernel/agents/azure_ai/azure_ai_agent.py:155

def _azure_function(spec: ToolSpec) -> ToolDefinition:
    # TODO(evmattso): Implement Azure Function tool support
    raise NotImplementedError("Azure Function tools are not yet supported with the Azure AI Agent Declarative Spec.")


@_register_tool("bing_grounding")
def _bing_grounding(spec: ToolSpec) -> BingGroundingTool:
    opts = spec.options or {}

    connections = spec.options.get("tool_connections")
    if not connections or not isinstance(connections, list) or not connections[0]:
        raise AgentInitializationException(f"Missing or malformed 'tool_connections' in: {spec}")
    conn_id = connections[0]

    market = opts.get("market", "")
    set_lang = opts.get("set_lang", "")
    count = opts.get("count", 5)
    if not isinstance(count, int):
        raise AgentInitializationException(f"'count' must be an integer in: {spec}")
    freshness = opts.get("freshness", "")

    return BingGroundingTool(connection_id=conn_id, market=market, set_lang=set_lang, count=count, freshness=freshness)


@_register_tool("code_interpreter")
def _code_interpreter(spec: ToolSpec) -> CodeInterpreterTool:
    file_ids = spec.options.get("file_ids")
    return CodeInterpreterTool(file_ids=file_ids) if file_ids else CodeInterpreterTool()


@_register_tool("file_search")
def _file_search(spec: ToolSpec) -> FileSearchTool:
    vector_store_ids = spec.options.get("vector_store_ids")
    if not vector_store_ids or not isinstance(vector_store_ids, list) or not vector_store_ids[0]:
        raise AgentInitializationException(f"Missing or malformed 'vector_store_ids' in: {spec}")
    return FileSearchTool(vector_store_ids=vector_store_ids)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Provide count as an integer literal.
  2. Coerce externally loaded config: int(opts['count']) before spec construction.
  3. Omit count to accept the default of 5.

Example fix

// before
options:
  tool_connections:
    - "/.../myBingConn"
  count: "5"

// after
options:
  tool_connections:
    - "/.../myBingConn"
  count: 5
Defensive patterns

Strategy: validation

Validate before calling

def coerce_count(opts: dict):
    c = opts.get("count", 5)
    if not isinstance(c, int):
        raise TypeError("count must be int")
    return c

Type guard

def count_is_int(opts: dict) -> bool:
    return isinstance(opts.get("count", 5), int)

Prevention

When it happens

Trigger: Setting count as a string (e.g. "5") or float in the declarative spec, typically from untyped config injection.

Common situations: Config templating injects numbers as strings; YAML scalar quoted as a string; copy-paste from a JSON sample.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/353a0cc6f9da5433. Report an issue: GitHub.