Skip to content

Grok only works with tools #3114

@filipre

Description

@filipre

Hi!

It looks like, that Grok or openai.LLM.with_x_ai only works when at least one tool is passed to the provided agent (see example below). Otherwise I always get this error message

livekit.agents._exceptions.APIStatusError: Error code: 400 - {'code': 'Client specified an invalid argument', 'error': 'Invalid request content: A tool_choice was set on the request but no tools were specified.'} (status_code=400, request_id=None, body=Invalid request content: A tool_choice was set on the request but no tools were specified., retryable=True)

Am I doing something wrong or is this a bug? Thanks for the help!

Minimal Code Example

# imports ...

@function_tool
async def lookup_weather(
    context: RunContext,
    location: str,
):
    """Used to look up weather information."""

    return {"weather": "sunny", "temperature": 70}


async def entrypoint(ctx: JobContext):
    await ctx.connect()

    agent = Agent(
        instructions="You are a friendly voice assistant built by LiveKit.",
        tools=[lookup_weather], # <- always needs to be a non-empty list
    )
    stt = ...
    llm = openai.LLM.with_x_ai(
        model="grok-3-mini-fast",
        temperature=0.5,
        tool_choice="auto", # <- doesn't help
    )
    tts = ...
    session = AgentSession(
        stt=stt,
        llm=llm,
        tts=tts,
    )

    await session.start(agent=agent, room=ctx.room)
    await session.generate_reply(instructions="greet the user and ask about their day")


if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))

Tests

Here is a test matrix

toolsArgument tool_choice Argument Result
[lookup_weather] not given ✅ Agent uses tool
[lookup_weather] auto ✅ Agent uses tool
[lookup_weather] none ✅ Agent doesn't use tool
[] not given ❌ 400 Error
[] auto ❌ 400 Error
[] none ❌ 400 Error
None not given ❌ 400 Error
None auto ❌ 400 Error
None none ❌ 400 Error

Dependencies

➜  livekit-grok git:(main) ✗ uv pip freeze
aiofiles==24.1.0
aiohappyeyeballs==2.6.1
aiohttp==3.12.15
aiosignal==1.4.0
annotated-types==0.7.0
anyio==4.10.0
attrs==25.3.0
av==15.0.0
certifi==2025.8.3
cffi==1.17.1
charset-normalizer==3.4.2
click==8.2.1
colorama==0.4.6
distro==1.9.0
docstring-parser==0.17.0
eval-type-backport==0.2.2
frozenlist==1.7.0
googleapis-common-protos==1.70.0
grpcio==1.74.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
idna==3.10
importlib-metadata==8.7.0
jiter==0.10.0
livekit==1.0.12
livekit-agents==1.2.4
livekit-api==1.0.5
livekit-blingfire==1.0.0
livekit-plugins-openai==1.2.4
livekit-protocol==1.0.5
multidict==6.6.3
nest-asyncio==1.6.0
numpy==2.3.2
openai==1.99.4
opentelemetry-api==1.36.0
opentelemetry-exporter-otlp==1.36.0
opentelemetry-exporter-otlp-proto-common==1.36.0
opentelemetry-exporter-otlp-proto-grpc==1.36.0
opentelemetry-exporter-otlp-proto-http==1.36.0
opentelemetry-proto==1.36.0
opentelemetry-sdk==1.36.0
opentelemetry-semantic-conventions==0.57b0
pillow==11.3.0
prometheus-client==0.22.1
propcache==0.3.2
protobuf==6.31.1
psutil==7.0.0
pycparser==2.22
pydantic==2.11.7
pydantic-core==2.33.2
pyjwt==2.10.1
python-dotenv==1.1.1
requests==2.32.4
sniffio==1.3.1
sounddevice==0.5.2
tqdm==4.67.1
types-protobuf==4.25.0.20240417
typing-extensions==4.14.1
typing-inspection==0.4.1
urllib3==2.5.0
watchfiles==1.1.0
websockets==15.0.1
yarl==1.20.1
zipp==3.23.0

Related Issues

Possibly google/adk-python#952 but not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions