> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thesys.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrating CrewAI with Thesys

> Give your CrewAI agents interactive UI components, dynamic workflows, and live dashboards powered by Thesys C1

Supercharge your CrewAI agents with Generative UI powered by C1 by Thesys.
Instead of limiting agents to text responses, you can render interactive UIs, create dynamic workflows,
and plug in real-time dashboards - all generated on the fly.

<Note>
  This guide assumes you have basic knowledge of CrewAI.
  You'll also need a Thesys API key from the [C1 Console](https://console.thesys.dev/keys).
</Note>

<Steps>
  <Step title="Create a new CrewAI agent">
    You can follow the [CrewAI Quickstart](https://docs.crewai.com/en/quickstart) to create a new CrewAI agent.

    ```bash theme={null}
    crewai create crew crewai-genui
    cd genui-agent
    ```
  </Step>

  <Step title="Create a new LLM class for Thesys">
    Extend the [`BaseLLM`](https://docs.crewai.com/en/learn/custom-llm) class to create a new LLM class for Thesys.

    ```python src/crewai-genui/thesys_llm.py [expandable] theme={null}
    from crewai import BaseLLM, Task
    import os
    import requests
    from typing import List, Optional, Union, Dict, Any

    class ThesysLLM(BaseLLM):
        def __init__(self, model: str="c1/anthropic/claude-sonnet-4/v-20250815", temperature: Optional[float] = None):
            super().__init__(model=model, temperature=temperature)
            self.endpoint = "https://api.thesys.dev/v1/embed"
            self.api_key = os.getenv("THESYS_API_KEY")

        def call(
            self,
            messages: Union[str, List[Dict[str, str]]],
            tools: Optional[List[dict]] = None,
            **kwargs: Any
        ) -> str:
            """Call the LLM with the given messages."""
            # Convert string to message format if needed
            if isinstance(messages, str):
                messages = [{"role": "user", "content": messages}]

            # Prepare request
            payload = {
                "model": self.model,
                "messages": messages,
                "temperature": self.temperature,
            }

            # Add tools if provided and supported
            if tools and self.supports_function_calling():
                payload["tools"] = tools

            # Make API call
            response = requests.post(
                self.endpoint + "/chat/completions",
                headers={
                    "Authorization": f"Bearer {self.api_key}",
                    "Content-Type": "application/json"
                },
                json=payload,
                timeout=300
            )
            response.raise_for_status()

            result = response.json()
            return result["choices"][0]["message"]["content"]
    ```
  </Step>

  <Step title="Update the reporting agent to use Thesys">
    In the `crew.py` file, the `researcher` and `reporting_analyst` agents would be defined. The job of
    of the `reporting_analyst` agent is to analyze the research and provide a summary of the findings.
    This is the perfect place to use Thesys as the LLM and generate a properly formatted report complete with
    charts and tables rather than just a plain text response.

    So lets go ahead and update the `reporting_analyst` agent to use Thesys.

    ```python src/crewai-genui/crew.py {5, 12} theme={null}
    @CrewBase
    class CrewaiGenUI:
        def __init__(self):
            super().__init__()
            self.thesys = ThesysLLM()

        @agent
        def reporting_analyst(self) -> Agent:
            return Agent(
                config=self.agents_config['reporting_analyst'], # type: ignore[index]
                verbose=True,
                llm=self.thesys
        )
    ```
  </Step>

  <Step title="Rendering the response">
    Now that we have the `reporting_analyst` agent using Thesys, we need to render the response.
    There are multiple ways to go about it but for this guide we will use the [Streamlit SDK](/guides/frameworks/streamlit)
    to render the response.

    First we need to install the dependencies.

    ```bash theme={null}
    pip install streamlit streamlit-thesys
    ```

    And then we need to update the `main.py` file to serve a streamlit app.

    ```python src/crewai-genui/main.py theme={null}
    import streamlit as st
    import streamlit_thesys as thesys

    def streamlit_app():
        # Streamlit app
        st.title("CrewAI Research & Reporting")
        topic = st.text_input("Enter topic:", value="AI LLMs")

        if st.button("Run Analysis"):
            inputs = {
                'topic': topic,
                'current_year': str(datetime.now().year)
            }

            with st.spinner("Running analysis..."):
                try:
                    result = CrewaiGenui().crew().kickoff(inputs=inputs)
                    thesys.render_response(result.raw if hasattr(result, 'raw') else str(result))
                except Exception as e:
                    st.error(f"Error: {e}")

    if __name__ == "__main__":
        streamlit_app()

    ```
  </Step>

  <Step title="Run the app">
    ```bash theme={null}
    export THESYS_API_KEY=<your-api-key>
    streamlit run main.py
    ```

    This will start the Streamlit app at `http://localhost:8501` and you should be able to run your crewai agent
    using the UI.
  </Step>
</Steps>

<Card title="View the code" icon="github" href="https://github.com/thesysdev/examples/tree/main/crewai_genui">
  Find more examples and complete code on our GitHub repository.
</Card>
