"Context" Problem

Hello!

I have this problem, it says:

AttributeError: ‘str’ object has no attribute ‘get’

I am new to CrewAI and I would like to know what I could do to fix it, here is the whole error:

(smart-agents-dev) PS C:\Users\IA-User\Documents\smart-agents-dev\smart_agents> crewai run
Running the Crew
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\IA-User\Documents\smart-agents-dev\smart_agents\src\smart_agents\main.py”, line 26, in run
SmartAgentsCrew().crew().kickoff(inputs=inputs)
^^^^^^^^^^^^^^^^^
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 35, in init
self.map_all_task_variables()
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 133, in map_all_task_variables
self._map_task_variables(
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 155, in _map_task_variables
if context_list := task_info.get(“context”):
^^^^^^^^^^^^^
AttributeError: ‘str’ object has no attribute ‘get’
An error occurred while running the crew: Command ‘[‘poetry’, ‘run’, ‘run_crew’]’ returned non-zero exit status 1.

@mkliangcoIA What’s the full command you ran? Can you show us the pyproject.toml file?

the command is crewai run

and then here is the pyproject.toml file:

[tool.poetry]
name = “smart_agents”
version = “0.1.0”
description = “smart-agents using crewAI”
authors = [“Your Name you@example.com”]

[tool.poetry.dependencies]
python = “>=3.10,<=3.13”
crewai = { extras = [“tools”], version = “>=0.70.1,<1.0.0” }

[tool.poetry.scripts]
smart_agents = “smart_agents.main:run”
run_crew = “smart_agents.main:run”
train = “smart_agents.main:train”
replay = “smart_agents.main:replay”
test = “smart_agents.main:test”

[build-system]
requires = [“poetry-core”]
build-backend = “poetry.core.masonry.api”

am i supposed to do crewai install again? Thank you

The correct command is: poetry run smart_agents or poetry run run_crew

Hi rokbenko, the error still persists and i have tried both commands.

(smart-agents-dev) PS C:\Users\IA-User\Documents\smart-agents-dev\smart_agents> poetry run smart_agents
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\IA-User\Documents\smart-agents-dev\smart_agents\src\smart_agents\main.py”, line 26, in run
SmartAgentsCrew().crew().kickoff(inputs=inputs)
^^^^^^^^^^^^^^^^^
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 35, in init
self.map_all_task_variables()
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 133, in map_all_task_variables
self._map_task_variables(
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 155, in _map_task_variables
if context_list := task_info.get(“context”):
^^^^^^^^^^^^^
AttributeError: ‘str’ object has no attribute ‘get’

For more context, I have a json file and csv file for the inputs.

Let’s go step-by-step.

Step 1: Run poetry install (Note: It might take a looooong time!)
Step 2: Run poetry shell
Step 3: Run poetry run smart_agents

After you do all three steps, let me know if you still have a problem.

Thanks for the fast reply. On the other hand, i’ve already installed poetry so it did not take long. Here is what transpired, and I am still getting the same issues. Thank you for your help and patience.

(smart-agents-dev) PS C:\Users\IA-User\Documents\smart-agents-dev\smart_agents> poetry install
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: smart_agents (0.1.0)
(smart-agents-dev) PS C:\Users\IA-User\Documents\smart-agents-dev\smart_agents> poetry shell
Virtual environment already activated: C:\Users\IA-User\Documents\smart-agents-dev
(smart-agents-dev) PS C:\Users\IA-User\Documents\smart-agents-dev\smart_agents> poetry run smart_agents
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\IA-User\Documents\smart-agents-dev\smart_agents\src\smart_agents\main.py”, line 26, in run
SmartAgentsCrew().crew().kickoff(inputs=inputs)
^^^^^^^^^^^^^^^^^
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 35, in init
self.map_all_task_variables()
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 133, in map_all_task_variables
self._map_task_variables(
File “C:\Users\IA-User\Documents\smart-agents-dev\Lib\site-packages\crewai\project\crew_base.py”, line 155, in _map_task_variables
if context_list := task_info.get(“context”):
^^^^^^^^^^^^^
AttributeError: ‘str’ object has no attribute ‘get’

Something is wrong with the way you pass inputs to the crew, I guess. Can you show the relevant code?

Sure, thanks for your patients.

Here is a snippet of my inputs from main.py

with open(‘…/references/esi-sample.json.json’, ‘r’) as file:
data = json.load(file)

df = pd.read_csv(‘…/references/country_sanction_list.csv’)

def run():
“”"
Run the crew.
“”"
inputs = {
‘ESI’ : data,
‘sanction_country’ : df
}
SmartAgentsCrew().crew().kickoff(inputs=inputs)

Then this is the snippet for my crew:

@CrewBase
class SmartAgentsCrew():
“”“SmartAgents crew”“”

@agent
def data_extractor(self) -> Agent:
	return Agent(
		config=self.agents_config['data_extractor'],
		# tools=[MyCustomTool()], # Example of custom tool, loaded on the beginning of file
		verbose=True,
		llm = llm_ollama
	)

@agent
def sanction_checker(self) -> Agent:
	return Agent(
		config=self.agents_config['sanction_checker'],
		verbose=True,
		llm = llm_ollama
	)

@task
def data_extracting_task(self) -> Task:
	return Task(
		config=self.tasks_config['data_extracting_task'],
		agent = self.data_extractor()
	)

@task
def sanction_task(self) -> Task:
	return Task(
		config=self.tasks_config['sanction_task'],
		agent = self.sanction_checker(),
		output_file='report.md'
	)

@crew
def crew(self) -> Crew:
	"""Creates the SmartAgents crew"""
	return Crew(
		agents=self.agents, # Automatically created by the @agent decorator
		tasks=self.tasks, # Automatically created by the @task decorator
		process=Process.sequential,
		verbose=True,
		# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
	)

That’s basically it.

Is what I sent sufficient? Thanks

What version are you running?

Seems like something is wrong with how you defined context. Context should point to tasks. So if you go to your tasks.yaml, do you have context defined there ?

Hi! Sorry for the late response.

My crewai version is 0.70.1
poetry is 1.8.4
python 3.11.9

Hi! It seems so. How do I define a context?

My task.yaml looks like this:

data_extracting_task:
description: >
From the ESI File {ESI}, extract the Booking Number information from the Booking Number field.
expected_output: >
Booking Number :
agent: data_extractor

sanction_task:
description: >
Instructions:
1. From the ESI File {ESI} extract every country name mentioned.
2. Cross-reference the extracted country names with the country names column in the list of sanctioned countries file {sanction_country}.
3. If there is a match, print there is a match.
expected_output: >
Extracted Country Names - Country Status
agent: sanction_agent

Hi team!

Thank you for all your help, I’ve solved the issue by re-creating my crew and then converting my dateframe to be a dictionary.

You guys have been huge help for me. Thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.